http://blog.csdn.net/pipisorry/article/details/39831419
问题:
linux中find命令查找时不包含某些目录
find 命令忽略某个或多个子目录的方法
在linux中用find 进行查找的时候,有时候需要忽略某些目录不查找,可以使用 -prune 参数来进行过滤,要忽略的路径参数必须紧跟着搜索的路径之后,否则该参数无法起作用。
eg:
[email protected]:/tmp1#find ./ -type f #/tmp1目录下所有文件夹里面的所有文件 ./file ./1/1.cpp ./2/2.cpp [email protected]:/tmp1#find ./ -path ./1 -prune -o -type f -print #/tmp1中查找文件但忽略文件夹/1中的文件 ./file ./2/2.cpp [email protected]:/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
时间: 2024-10-14 01:29:29