您的位置:首页 > 其它

对find参数-prune的理解

2015-08-27 15:04 246 查看
find . ! -name "." -type d -prune -o -type f -iname "*.zip" -print

-path "/usr/sam" -prune -o -print 是 -path "/usr/sam" -a -prune -o -print 的简写表达式按顺序求值, -a 和 -o 都是短路求值,与 shell 的 && 和 || 类似如果 -path "/usr/sam" 为真,则求值 -prune , -prune 返回真,与逻辑表达式为真;否则不求值 -prune,与逻辑表达式为假。如果 -path "/usr/sam" -a -prune 为假,则求值 -print ,-print返回真,或逻辑表达式为真;否则不求值
-print,或逻辑表达式为真。

这个表达式组合特例可以用伪码写为

if -path "/usr/sam" then

-prune

else

-print


理解:-prune前面的判定条件为真时,会结束当前文件的判定过程并且当它为目录时,会阻断对其中的文件及子目录的遍历。

当find命令末尾没有-print时,默认的-print是绑定整个find命令的,所以会有输出,而显式的-print是绑定-prune之后的判定条件的,当-prune之前的条件通过时不会有输出

版权声明:本文为博主原创文章,未经博主允许不得转载。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: