码迷,mamicode.com
首页 > 系统相关 > 详细

linux中find命令详解

时间:2014-10-06 23:05:51      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:linux   find   

http://blog.csdn.net/pipisorry/article/details/39831419

问题:

linux中find命令查找时不包含某些目录

find 命令忽略某个或多个子目录的方法

在linux中用find 进行查找的时候,有时候需要忽略某些目录不查找,可以使用 -prune 参数来进行过滤,要忽略的路径参数必须紧跟着搜索的路径之后,否则该参数无法起作用。

eg:

root@ubuntu:/tmp1#find ./ -type f    #/tmp1目录下所有文件夹里面的所有文件
./file
./1/1.cpp
./2/2.cpp
root@ubuntu:/tmp1#find ./ -path ./1 -prune -o -type f -print    #/tmp1中查找文件但忽略文件夹/1中的文件
./file
./2/2.cpp
root@ubuntu:/tmp1#find ./ \( -path ./1 -o -path ./2 \) -prune -o -type f -print    #/tmp1中查找文件同时忽略文件夹/1 /2中的文件
./file

man find

...
-path pattern
              File  name matches shell pattern pattern.  The metacharacters do
              not treat `/' or `.' specially; so, for example,
                        find . -path "./sr*sc"
              will print an entry for a directory called `./src/misc' (if  one
              exists).   To  ignore  a whole directory tree, use -prune rather
              than checking every file in the tree.  For example, to skip  the
              directory  `src/emacs'  and  all files and directories under it,
              and print the names of the other files found, do something  like
              this:
                        find . -path ./src/emacs -prune -o -print
              Note that the pattern match test applies to the whole file name,
              starting from one of the start points named on the command line.
              It  would  only  make sense to use an absolute path name here if
              the relevant start point is also an absolute path.   This  means
              that this command will never match anything:
                        find bar -path /foo/bar/myfile -print
              The  predicate -path is also supported by HP-UX find and will be
              in a forthcoming version of the POSIX standard.
...

也可以使用参数-wholename,不过不建议了

 -wholename pattern
              See -path.    This alternative is less portable than -path.

from:http://blog.csdn.net/pipisorry/article/details/39831419


linux中find命令详解

标签:linux   find   

原文地址:http://blog.csdn.net/pipisorry/article/details/39831419

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!