find排除某目录或文件
2013-05-05 06:29
211 查看
仅转载,未整理
linux find prune exec 排除某目录或文件 执行
查找cache目录下不是html的文件find ./cache ! -name '*.html' -type f列出当前目录下的目录名,排除includes目录,后面的-print不能少
find . -path './includes' -prune -o -type d -maxdepth 1 -print
排除多个目录,”(“前是带”\”的
find / \( -path /home/ -o -path /root \) -prune -nouser -type f -exec ls -l {} \;
find查找文件的时候排除某个或几个文件或目录
比如要在/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
避开多个文件夹
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
linux下的常用命令find,加上不同的参数,可以使你很容易的找到需要的文件,但是有些时候,你在查找文件的同时,可能不需要在某文件夹下查找,这时候-prune就用上了。
比如在当前目录下寻找pl后缀的文件,不在scripts下寻找。
find . -path './scripts' -prune -o -name '*.pl' -print
相关文章推荐
- find查找文件的时候排除某个或几个文件或目录使用笔记
- linux find 排除某目录或文件 执行
- find查找时排除目录及文件
- linux find prune exec 排除某目录或文件 执行
- linux find prune exec 排除某目录或文件 执行
- linux find prune exec 排除某目录或文件 执行
- find查找文件的时候排除某个或几个文件或目录 (转载)
- find查找文件的时候排除某个或几个文件或目录
- find查找文件的时候排除某个或几个文件或目录
- find排除文件或目录搜索
- find查找文件的时候排除某个或几个文件或目录
- linux find prune exec 排除某目录或文件 执行
- find 排除目录
- linux之find命令--查找目录及文件
- find命令查找目录和文件之exec
- tar 打包并压缩文件,排除文件前缀目录
- tar 排除某个文件或目录
- find grep xargs 查找某目录下包含某字符串的文件
- find查找文件和目录
- grep时排除指定的文件和目录