免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3776 | 回复: 5
打印 上一主题 下一主题

[新手入门] find命令不递归查找的疑问! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-02 16:22 |只看该作者 |倒序浏览
在网上看了很多关于prune的用法,但是结果好像还是不尽如人意!
在网上看到一个语句:
find .  ! -name "." -type d -prune -o -type f -name "*.txt" -print
就是只查找当前目录,不包括下N级目录下的txt结尾的文件!

但是对于上面的语句,有点疑惑,不是很看得懂!
不知道那位能解释一下,特别是前面的“!”
还有个问题,既然print是find的默认选项,为什么以上语句必须写print!!!
很多人会问为什么不用ls,因为ls会出现long ×××××的报错;

论坛徽章:
0
2 [报告]
发表于 2009-07-02 16:39 |只看该作者
! Expression - The negation of an expression ('!' is the unary NOT operator).

man find
就清楚了.

论坛徽章:
0
3 [报告]
发表于 2009-07-02 16:43 |只看该作者
我知道!是取反的意思,但是在这个例子里我就是不明白!

包括print必须加上,我记得aix4.3以上print是可以不用显式的写出来的!

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
4 [报告]
发表于 2009-07-02 17:33 |只看该作者
find .  ! -name "." -type d -prune -o -type f -name "*.txt"
相当于
find .  \( ! -name "." -type d -prune -o -type f -name "*.txt" \) -print
相当于
find .  ! -name "." -type d -prune -print -o -type f -name "*.txt" -print

find .  ! -name "." -type d -prune -o -type f -name "*.txt" -print
相当于
find .  \( ! -name "." -type d -prune \) -o \( -type f -name "*.txt" -print \)

所以
find .  ! -name "." -type d -prune -o -type f -name "*.txt"

find .  ! -name "." -type d -prune -o -type f -name "*.txt" -print
不一样

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
5 [报告]
发表于 2009-07-02 17:35 |只看该作者
建议你去shell版问问,那边有几个高手对find研究得多些。

论坛徽章:
0
6 [报告]
发表于 2009-07-03 08:44 |只看该作者
谢谢楼上两位的解答,我再去shell版问问!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP