bash 从find linux中排除一个目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45856411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:24:35  来源:igfitidea点击:

Exclude a directory from find linux

linuxbashfind

提问by St.Antario

I want to exclude all directories from the findcommand target. I can use this:

我想从find命令目标中排除所有目录。我可以用这个:

find / -not -path /my/path -name name

But this still keep looking at all subdirectories of /my/path. Is there a way to exclude the directory and all its subdirectories from find?

但这仍然会继续查看/my/path. 有没有办法从目录中排除目录及其所有子目录find

回答by Nahuel Fouilleul

with -prune

-prune

find . -name directory_to_exclude -prune -o ...

to exclude many directories

排除许多目录

find . \( -name dir1_to_exclude -o -name dir2 ... \) -prune -o ...