我用更简单的解释,手册页错了.它应该说
If the whole expression contains no actions other than -prune
or -print, -print is performed on all files for which the whole expression is true.
它也可能包含-quit的警告,这是一个动作,但它会导致-find立即退出.因此,即使为整个表达式添加了隐式-print,它也永远不会被实际执行.
posix find man page包含更清晰的解释,但它没有扩展的gnu版本那么多的动作.
If no expression is present, -print shall be used as the expression. Otherwise, if the given expression does not contain any of the primaries -exec, -ok, or -print, the given expression shall be effectively replaced by:
( given_expression ) -print
在gnu调用的操作中,posix仅定义-exec,-ok,-print和-prune.它没有任何扩展的动作-delete,-ls等……所以定义只通过省略-prune来匹配纠正的gnu.
以下是使用所有gnu查找操作的一些示例,这些操作证明了这一点.对于所有人,请考虑以下文件结构
$tree
.
└── file
-删除
$find -name file -delete
$
-exec命令;
$find -name file -exec echo '-exec is an action so an implicit -print is not applied' \;
-exec is an action so an implicit -print is not applied
$
-execdir命令{}
$find -name file -exec echo 'This should print the filename twice if an implicit -print is applied: ' {} +
This should print the filename twice if an implicit -print is applied: ./file
$
-fls
$find -name file -fls file
$
-fprint
$find -name file -fprint file
$
-ls
$find -name file -ls
1127767338 0 -rw-rw-r-- 1 user user 0 May 6 07:15 ./file
$
-ok命令;
$find -name file -ok echo '-ok is an action so an implicit -print is not applied' \;
< echo ... ./file > ? y
-ok is an action so an implicit -print is not applied
$
-okdir命令;
$find -name file -okdir echo '-okdir is an action so an implicit -print is not applied' \;
< echo ... ./file > ? y
-okdir is an action so an implicit -print is not applied
$
-打印
#./file would be printed twice if an implicit `-print was applied`
$find -name file -print
./file
$
-print0
#./file would be printed twice if an implicit `-print was applied`
$find -name file -print0
./file$
-printf
$find -name file -printf 'Since -printf is an action the implicit -print is not applied\n'
Since -printf is an action the implicit -print is not applied
$
-修剪
$find -name file -prune
./file
$
-放弃
$find -name file -quit
$find -D opt -name file -quit
...
Optimized command line:
( -name file [0.1] -a [0.1] -quit [1] ) -a [0.1] -print [1]