免费注册 查看新帖 |

Chinaunix

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

find 的 -prune用法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-09-19 22:43 |只看该作者 |倒序浏览
-prune                    If the current entry is a directory, cause
                               find to skip that directory.  This can be
                               useful to avoid walking certain directories,
                               or to avoid recursive loops when using cpio
                               -p.  Note, however, that -prune is useless if
                               the -depth option has also been given.  See
                               the description of -only and the EXAMPLES
                               section, below, for more information.  Always
                               true.


想avoid 倒底应该怎么用??

论坛徽章:
0
2 [报告]
发表于 2007-09-20 08:42 |只看该作者
奇怪, 不是刚讨论了这个问题吗:
-(dearvoid@LinuxEden:Forum)-(~/tmp/abcde)-
[12036 0]
; find -name 123
./a/123
./b/123
./123
-(dearvoid@LinuxEden:Forum)-(~/tmp/abcde)-
[12036 0]
; find -path ./a -prune -o -name 123 -print
./b/123
./123
-(dearvoid@LinuxEden:Forum)-(~/tmp/abcde)-
[12036 0]
; find -path './[ab]' -prune -o -name 123 -print
./123
-(dearvoid@LinuxEden:Forum)-(~/tmp/abcde)-
[12036 0]
; bye

论坛徽章:
0
3 [报告]
发表于 2007-09-20 09:13 |只看该作者
本人较愚钝,试翻译如下:
-prune                    If the current entry is a directory, cause
                               find to skip that directory.  This can be
                               useful to avoid walking certain directories,
                               or to avoid recursive loops when using cpio
                               -p.  Note, however, that -prune is useless if
                               the -depth option has also been given.  See
                               the description of -only and the EXAMPLES
                               section, below, for more information.  Always
                               true.
如果当前条目是一个目录。会使find 跳过该条目。这个选项很有用,当避免遍历指定目录,或是在使用 cpio -p 的时候避免递归循环。 注意,如果-depth选项在使用的时候. -prune是无效的。请看 -only 选项,并看列子一章。以获得更多的信息。 总是真

  丝毫没有看到是怎么使用的? 你怎么知道是用 -path这样用呢? 怎么 -name 前面还是加 -o 呢?

论坛徽章:
0
4 [报告]
发表于 2007-09-20 09:39 |只看该作者
我试过了,如果目录层级结构为

      d1
d11 d12 d13
f1 f2 f3 f4

在d1目录里
如果我用 find .  显示所有文件
find . -path ./d11  则显示 ./d11
find . -path ./d11 -prune 仍然如此
find . -path ./d11 -prune -o -name "*.*" 就可以完全显示了?

搞不懂? 为什么会这样?

论坛徽章:
0
5 [报告]
发表于 2007-09-20 15:06 |只看该作者
指导一下,谢谢!

论坛徽章:
0
6 [报告]
发表于 2007-09-21 08:46 |只看该作者
这个解释起来有点儿绕, find 的 manual 里面有这么一句话可以仔细体味一下:
If the expression contains no actions other than -prune, -print is
performed on all files for which the expression is true.

-prune 的表现行为会 confuse 许多人, 其实我们大可避免使用 -prune, -not -path 可以达到相同的效果, 只是有些 performance 的牺牲:
-(dearvoid@LinuxEden:Forum)-(~/tmp/abcde)-
[31048 0]
; find
.
./a
./a/123
./b
./b/123
./123
-(dearvoid@LinuxEden:Forum)-(~/tmp/abcde)-
[31048 0]
; find -not -path './a/*' -name 123
./b/123
./123
-(dearvoid@LinuxEden:Forum)-(~/tmp/abcde)-
[31048 0]
; find -not -path './[ab]/*' -name 123
./123
-(dearvoid@LinuxEden:Forum)-(~/tmp/abcde)-
[31048 0]
; bye
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP