查找路径不包含单词的文件

Find files whose path doesn't contain a word

我正在尝试列出所有 .hpp 文件,但路径中包含单词的文件, 例如:

find -name '*.hpp' 会给出

folder1/folder2/something.hpp
folder1/folder3/something.hpp
folder1/folder4/something.hpp

我想排除 folder2 中的文件,以便只有这些文件:

folder1/folder3/something.hpp
folder1/folder4/something.hpp

只需否定一个-path条件:

find -name '*.hpp' -not -path '*/folder2/*'

要排除几个目录,要么重复条件:

find -name '*.hpp' -not -path '*/folder2/*' -not -path '*/folder3/*'

或在正则表达式中使用替代方法:

find -name '*.hpp' -not -regex '.*/\(folder2\|folder3\)/.*'