问题
I am trying to list all the .hpp
files but those whose path contain a word,
for example :
find -name '*.hpp'
would give
folder1/folder2/something.hpp
folder1/folder3/something.hpp
folder1/folder4/something.hpp
I'd like to exclude the files in the folder2 in order to have only these :
folder1/folder3/something.hpp
folder1/folder4/something.hpp
回答1:
Just negate a -path
condition:
find -name '*.hpp' -not -path '*/folder2/*'
To exclude several directories, either repeat the condition:
find -name '*.hpp' -not -path '*/folder2/*' -not -path '*/folder3/*'
Or use alternative in a regex:
find -name '*.hpp' -not -regex '.*/\(folder2\|folder3\)/.*'
来源:https://stackoverflow.com/questions/31026599/find-files-whose-path-doesnt-contain-a-word