查找文件其路径不包含字(Find files whose path doesn't cont

2019-10-29 01:47发布

我想列出所有的.hpp文件,但那些路径包含一个词,例如:

find -name '*.hpp'会给

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

我想排除的文件夹2中的文件,以只有这些:

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

Answer 1:

只是否定一个-path条件:

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

要排除多个目录,重复上述条件:

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

或正则表达式使用替代:

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


文章来源: Find files whose path doesn't contain a word
标签: linux path find