查找路径不包含单词的文件 [英] Find files whose path doesn't contain a word

查看:274
本文介绍了查找路径不包含单词的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图列出所有 .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


解决方案

只要取消 -path 条件:

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



<要排除几个目录,可以重复这个条件:

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

正则表达式:

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


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

解决方案

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\)/.*' 

这篇关于查找路径不包含单词的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆