gnu linux 使用find,linux – GNU find:默认操作何时适用?

我用更简单的解释,手册页错了.它应该说

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]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值