#在当前目录下排除abc目录,查找所有文件
find . -path "./abc" -prune -o -print
#在当前目录下排除abc目录,查找所有以.txt结尾的文件【方式一】
find . -path "./abc" -prune -o -name "*.txt" -print
#在当前目录下排除abc目录,查找所有以.txt结尾的文件【方式二】
find . -name ".txt" -not -path "./abc/"
#在当前目录下排除abc和def目录,查找所有以.txt结尾的文件
find . ( -path ./abc -o -path ./def ) -prune -o -name "*.txt" -print
#在当前目录下排除abc目录和def/h.txt文件,查找所有以.txt结尾的文件
find . ( -path ./abc -o -path ./def/h.txt ) -prune -o -name "*.txt" -print
#在当前目录下排除abc目录和def/h.txt文件和jk目录,查找所有以.txt结尾的文件
find . ( -path ./abc -o -path ./def/h.txt -o -path ./jk ) -prune -o -name "*.txt" -print
#在当前目录下查找所有不是以.html结尾的文件
find . ! -name "*.html" -type f
使用-prune
开关。例如,如果要排除misc
目录,只需将a添加-path ./misc -prune -o
到您的find命令中:
find . -path ./misc -prune -false -o -name '*.txt'
这是带有多个目录的示例:
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -false -o -name '*.txt'
在这里,我们排除./dir1,./dir2和./dir3在当前目录中,因为在find
表达它是作用于标准的动作-path dir1 -o -path dir2 -o -path dir3
(如果DIR1或DIR2或DIR3),以相与type -d
。
要排除任何级别的目录名称,请使用-name
:
<span style="background-color:#f5f5f5"><span style="color:#4a4a4a"><code>find . -type d \( -name node_modules -o -name dir2 -o -path name \) -prune -false -o -name '*.json'</code></span></span>
文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/9059