我正在尝试使/usr/bin/find显示一些有意义的东西而不做任何类型的统计,到目前为止没有有用的结果.如果我强行抑制stat,发现停止下降到子目录中.
作为getdents syscall的手册页说,那里有d_type字段,所以find应该已经有了决策所需的一些信息.
无论-L,-H或其他任何选项,为什么需要stat.
解决方法:
使用来源,卢克!
在GNU查找源代码中(我正在查看版本4.2.2),遍历目录树的代码位于gnulib / lib / fts.c中.在第1123行,有以下评论:
Record what fts_read will have to do with this
entry. In many cases, it will simply fts_stat it,
but we can take advantage of any d_type information
to optimize away the unnecessary stat calls. I.e.,
if FTS_NOSTAT is in effect and we’re not following
symlinks (FTS_PHYSICAL) and d_type indicates this
is not a directory, then we won’t have to stat it
at all. If it is a directory, then (currently)
we stat it regardless, in order to get device and
inode numbers. Some day we might optimize that
away, too, for directories where d_ino is known to
be valid.
所以他们已经考虑过你描述的优化,但它没有实现.