我将使用更简单的解释,手册页错误。它应该改为
如果整个表达式不包含除 -prune 或 -print 之外的任何操作,则对整个表达式为 true 的所有文件执行 -print。
它还应该包含对-quit 的警告,这是一个动作,但它会导致-find 立即退出。因此,即使为整个表达式添加了隐式 -print,它也不会真正执行。
posix find man page 包含更清晰的解释,尽管它没有扩展的 gnu 版本那么多的操作。
如果不存在表达式,则应使用-print 作为表达式。否则,如果给定的表达式不包含任何主要的 -exec、-ok 或 -print,则给定的表达式应有效地替换为:
(给定表达式)-打印
在gnu 调用的动作中,posix 只定义了-exec、-ok、-print 和-prune。它没有任何扩展操作-delete、-ls 等...因此定义与更正后的gnu 匹配,只需省略-prune。
这里有一些使用 gnu find 动作的例子来证明这一点。对于所有考虑以下文件结构
$ tree
.
└── file
-删除
$ find -name file -delete
$
-执行命令;
$ 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]