Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何递归grep并忽略子目录的子目录?_Linux_Macos_Recursion_Grep - Fatal编程技术网

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

Linux 如何递归grep并忽略子目录的子目录?,linux,macos,recursion,grep,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

我已经熟悉了
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和其他StuffIDC

我的例子很简单,但在我的现实世界中,有很多子目录,所以我不可能只对每个子目录进行grep处理。

这将排除名为
idc
otherStuffIdc
的(子)目录

 grep -r pattern --exclude-dir=idc,otherStuffIdc

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


是否要从搜索中排除idc及其所有子目录?是!精确地我想排除
idc
otherStuffIdc
grep-r模式--exclude dir=idc
,这不起作用吗?这起作用了,我一定是早些时候弄糟了。谢谢@iamauserOn那是什么操作系统?Ubuntu 18.04.:)我只是在没有带花括号的情况下又试了一次,但没有成功。。奇怪的
grep -r pattern --exclude-dir={idc,otherStuffIdc}