这是从Ketan和daniel Kullman的答案以及我自己的研究得出的完整答案。
事实证明,大多数“功能”都是查询优化,因为find
它通常能够(几乎)对文件系统进行任意复杂的查询。
D_TYPE
该D_TYPE
功能的存在意味着find
在的支持下对该d_type
字段进行了编译struct dirent
。此字段是Linux也采用的BSD扩展,它在从readdir
和朋友返回的结构中提供文件类型(目录,文件,管道,套接字,字符/块设备等)。作为优化,find
可以lstat
在-type
用作过滤器表达式时使用它来减少或消除调用。
readdir
可能并不总是d_type
在某些文件系统上填充,因此有时lstat
仍然需要。
来自官方文档的更多信息:https : //www.gnu.org/software/findutils/manual/html_node/find_html/d_005ftype-Optimisation.html
O_NOFOLLOW
此选项将读取(enabled)
或(disabled)
。如果存在并启用,则此功能将实施一项安全措施,以防止find
某些TOCTTOU种族攻击。具体来说,它可以防止find
在执行目录遍历时遍历符号链接,如果在检查目录的文件类型之后但在输入目录之前用符号链接替换目录,则可能会发生这种情况。
启用此选项后,find
将用于open(..., O_NOFOLLOW)
在目录上仅打开真实目录,然后用于openat
在该目录中打开文件。
LEAF_OPTIMISATION
这种稍微模糊的优化允许find
通过使用父目录的链接计数来推断父目录的哪些子目录是目录,因为子目录(通过..
链接)将有助于父目录的链接数。在某些情况下,它将允许find
取消stat
呼叫。但是,如果文件系统或OS表示错误st_nlinks
,则可能导致find
产生伪造的结果(幸运的是,这种情况很少发生)。
官方文档中的更多信息:https : //www.gnu.org/software/findutils/manual/html_node/find_html/Leaf-Optimisation.html
FTS
启用后,此FTS
功能将导致find
使用fts
API遍历文件层次结构,而不是直接递归实现。
我尚不清楚优点fts
是什么,但FTS
基本上是find
到目前为止我所看到的所有默认版本中的默认值。
更多信息:https : //www.gnu.org/software/findutils/manual/html_node/find_html/fts.html,http : //man7.org/linux/man-pages/man3/fts.3.html
国会预算办公室
事实证明(在阅读find
daniel kullman建议的源代码之后),“ CBO”指的是查询优化级别(代表“基于成本的优化器”)。例如,如果我这样做find -O9001 --version
,我得到
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS() CBO(level=9001)
看着中的-O
选项man find
,我看到了
-Olevel
Enables query optimisation. The find program reorders tests to speed up execution while preserving the overall
effect; that is, predicates with side effects are not reordered relative to each other. The optimisations performed
at each optimisation level are as follows.
0 Equivalent to optimisation level 1.
1 This is the default optimisation level and corresponds to the traditional behaviour. Expressions are
reordered so that tests based only on the names of files (for example -name and -regex) are performed first.
2 Any -type or -xtype tests are performed after any tests based only on the names of files, but before any
tests that require information from the inode. On many modern versions of Unix, file types are returned by
readdir() and so these predicates are faster to evaluate than predicates which need to stat the file first.
3 At this optimisation level, the full cost-based query optimiser is enabled. The order of tests is modified
so that cheap (i.e. fast) tests are performed first and more expensive ones are performed later, if neces-
sary. Within each cost band, predicates are evaluated earlier or later according to whether they are likely
to succeed or not. For -o, predicates which are likely to succeed are evaluated earlier, and for -a, predi-
cates which are likely to fail are evaluated earlier.
The cost-based optimiser has a fixed idea of how likely any given test is to succeed. In some cases the probability
takes account of the specific nature of the test (for example, -type f is assumed to be more likely to succeed than
-type c). The cost-based optimiser is currently being evaluated. If it does not actually improve the performance
of find, it will be removed again. Conversely, optimisations that prove to be reliable, robust and effective may be
enabled at lower optimisation levels over time. However, the default behaviour (i.e. optimisation level 1) will not
be changed in the 4.3.x release series. The findutils test suite runs all the tests on find at each optimisation
level and ensures that the result is the same.
谜团已揭开!该选项为运行时值有点奇怪;通常,我希望--version
输出仅反映编译时选项。