find命令排除某些目录或文件

#在当前目录下排除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(如果DIR1DIR2DIR3),以相与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

(0)
郭靖的头像郭靖
上一篇 2023年6月16日 下午4:36
下一篇 2023年6月19日 下午4:22

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信