Find files whose path doesn't contain a word

北城余情 提交于 2020-01-25 17:23:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!