如何递归grep并忽略子目录的子目录?

时间:2018-01-19 15:53:51

标签: linux macos recursion grep

我已经熟悉grep -r "searchTerm" .并且我熟悉grep -r "searchTerm" exclude={subdir1, subdir2} .但是,我正在寻找一种通过子目录递归grep并忽略子目录的某些子目录的方法。

例如,如果目录结构如下:

/folder
   /subdir1
      /idc/file.js
      /files/file.js
      /otherStuffIdc/file.js
   /subdir2
      /idc/file2.js
      /files/file2.js
      /otherStuffIdc/file2.js
...

我如何能够排除idc和otherStuffIdc,因为这些文件夹是我开始搜索的根目录的子目录的子目录?

我的示例已经过简化,但在我的真实世界问题中,有很多很多subDir#因此我只能grep每个子目录是不可行的。

2 个答案:

答案 0 :(得分:2)

这将排除名称为def octal_print(s): charlist = list() for character in s: try: character.decode('ascii') charlist.append(character) except: charlist.append('\\'+oct(ord(character))[1:]) return ''.join(charlist) idc目录。

otherStuffIdc

答案 1 :(得分:0)

对我来说,这仅适用于(子)文件夹周围的花括号

grep -r pattern --exclude-dir={idc,otherStuffIdc}
相关问题