Chinaunix首页 | 论坛 | 博客
  • 博客访问: 438718
  • 博文数量: 52
  • 博客积分: 3193
  • 博客等级: 中校
  • 技术积分: 860
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-19 09:58
文章分类

全部博文(52)

文章存档

2012年(1)

2011年(9)

2009年(18)

2008年(24)

我的朋友

分类: LINUX

2009-11-08 23:01:43

比如要在/usr/sam目录下查找不在dir1子目录之内的所有文件

find /usr/sam -path "/usr/sam/dir1" -prune -o -print

find [-path ..] [expression] 在路径列表的后面的是表达式

-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

避开多个文件夹

方法1:

find /usr/sam \( -path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -print

圆括号表示表达式的结合。

\ 表示引用,即指示 shell 不对后面的字符作特殊解释,而留给 find 命令去解释其意义 [注意:\(及 \)后有空格]。

查找某一确定文件,-name等选项加在-o 之后

#find /usr/sam \(-path /usr/sam/dir1 -o -path /usr/sam/file1 \) -prune -o -name "temp" -print
 
 
方法2:
 排除uboot目录下除中lib_arm及lib_generic的所有lib_*目录
find $UBOOT  \
-path "$UBOOT/lib_*" ! \( -path "$UBOOT/lib_arm*" -o -path "$UBOOT/lib_generic*" \) -prune -o  \
-name "*.[chsS]" -print > $UBOOT/cscope.files
 
 
 
阅读(1532) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~