当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 7 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : find命令中的prune和or到底是怎么回事啊,弄了很长时间都没弄明白
帖子发表于 : 2012-04-13 15:29 
头像

注册: 2010-11-19 22:55
帖子: 413
送出感谢: 10
接收感谢: 1
执行命令:
代码:
find . -path "./applications*" -prune -o -name "*.jpg" -print

结果:
代码:
./application icons/wireshark.jpg
./86d6277f9e2f0708f73f26bfe924b899a901f253.jpg
./Wallpapers-room_com___The_Wood_Experiment_by_Delta909_1920x1200.jpg

把原来的那条命令后面的-print去掉后,结果:
代码:
./application icons/wireshark.jpg
./applications
./86d6277f9e2f0708f73f26bfe924b899a901f253.jpg
./Wallpapers-room_com___The_Wood_Experiment_by_Delta909_1920x1200.jpg


疑问:
1.为什么两次加-print结果不一样?-print不是find自动加上的吗?按我的想法看加不加应该结果都是一样的,因为find都会自动把-print加上去
2.我明明在find命令中指明了,不要搜索形如./applications*的文件夹(prune的功能不就是不深入指定文件夹中吗),为什么结果中还是会显示这类文件呢

先谢谢大家了


页首
 用户资料  
 
2 楼 
 文章标题 : Re: find命令中的prune和or到底是怎么回事啊,弄了很长时间都没弄明白
帖子发表于 : 2012-04-13 17:11 

注册: 2008-05-24 8:30
帖子: 1453
送出感谢: 2
接收感谢: 30
第2个问题,注意那个 s,application icons 不匹配 applications*,所以列出来了。


页首
 用户资料  
 
3 楼 
 文章标题 : Re: find命令中的prune和or到底是怎么回事啊,弄了很长时间都没弄明白
帖子发表于 : 2012-04-13 17:17 
头像

注册: 2005-08-14 21:55
帖子: 58428
地址: 长沙
送出感谢: 4
接收感谢: 274
If the expression contains no actions other than -prune, -print is per‐
formed on all files for which the expression is true.
所以不显示目录了。和-depth冲突。很少使用这-prune的。

多使用locate吧。
● type loc
loc 是 `locate -beLin 20' 的别名


_________________
● 鸣学


页首
 用户资料  
 
4 楼 
 文章标题 : Re: find命令中的prune和or到底是怎么回事啊,弄了很长时间都没弄明白
帖子发表于 : 2012-04-13 17:34 
头像

注册: 2011-06-07 14:20
帖子: 3866
系统: Mint18
送出感谢: 17
接收感谢: 65
对,多用locate,find是折磨硬盘呢


_________________
wiki: ubuntu 技巧


页首
 用户资料  
 
5 楼 
 文章标题 : Re: find命令中的prune和or到底是怎么回事啊,弄了很长时间都没弄明白
帖子发表于 : 2012-04-13 21:13 
头像

注册: 2010-11-19 22:55
帖子: 413
送出感谢: 10
接收感谢: 1
aerofox 写道:
第2个问题,注意那个 s,application icons 不匹配 applications*,所以列出来了。

感觉很奇怪,加不加-print不是应该结果一样吗?我记得find好像是自动加-print的


页首
 用户资料  
 
6 楼 
 文章标题 : Re: find命令中的prune和or到底是怎么回事啊,弄了很长时间都没弄明白
帖子发表于 : 2012-04-13 21:15 
头像

注册: 2010-11-19 22:55
帖子: 413
送出感谢: 10
接收感谢: 1
eexpress 写道:
If the expression contains no actions other than -prune, -print is per‐
formed on all files for which the expression is true.
所以不显示目录了。和-depth冲突。很少使用这-prune的。

多使用locate吧。
● type loc
loc 是 `locate -beLin 20' 的别名

谢谢啦,不过我想排除某个目录进行搜索,google了一下,大部分答案都是关于这个-prune的,所以就学了一下,弄了半下午也没弄出个所以然来


页首
 用户资料  
 
7 楼 
 文章标题 : Re: find命令中的prune和or到底是怎么回事啊,弄了很长时间都没弄明白
帖子发表于 : 2012-04-13 23:15 

注册: 2008-05-24 8:30
帖子: 1453
送出感谢: 2
接收感谢: 30
NewUserFF 写道:
aerofox 写道:
第2个问题,注意那个 s,application icons 不匹配 applications*,所以列出来了。

感觉很奇怪,加不加-print不是应该结果一样吗?我记得find好像是自动加-print的


man find 写道:
如果表达式没有包含 -prune 以外的动 作,当表达式为真时会执行 -print 动作。

-prune 如果没有给出 -depth 则返回 true; 不进入当前目录。

我想是这样的,当执行下面这条命令时,
代码:
find . -path "./applications*" -prune -o -name "*.jpg"

遇到 -prune 虽然不进入 ./applications* 目录下,但是它本身是返回 true 的,这样就会执行 -print 动作,把这个目录显示出来。
而包含 -print 动作,这个动作只跟后面的 -name 作 -and 连接。
两者的区别是下面两条命令的区别:
代码:
find . \( -path "./applications*" -prune -o -name "*.jpg" \) -print
find . -path "./applications*" -prune -o \( -name "*.jpg" \) -print


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 7 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 1 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译