如果想查找当前目录(/home/student)下的tmp.txt文件,但是想要避开sep目录:
find /home/student -path /home/student/sep -prune -o -name "tmp.txt" -print
sep后面不能加/ 即/home/student/sep/是错误的 如果当前目录为/home/student 也可以这样
find . -path ./sep -prune -o -name "tmp.txt" -print
总结:-path 只是匹配find出来的路径,可以通过使用匹配符号* [] ?等 例如:
[student@bioeng ~]$ find . -name file
./file
./dir/file
./dir/dir555/file
./dir/dir2/file
./dir/dir1/file
[student@bioeng ~]$
[student@bioeng ~]$ find . -path "*dir[12]" -prune -o -name file -print
./file
./dir/file
./dir/dir555/file
[student@bioeng ~]$ [student@bioeng ~]$ find . -path "*dir*" -prune -o -name file -print
./file
[student@bioeng ~]$
转自: http://blog.youkuaiyun.com/imfinger/article/details/6371601
本文介绍如何利用find命令避开sep目录并查找指定文件tmp.txt于/home/student路径下,通过使用-path选项和匹配符号如*、[]、?进行路径匹配。举例展示了如何在不同条件下使用find命令进行文件查找。
685

被折叠的 条评论
为什么被折叠?



