简体   繁体   English

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

[英]How to grep recursively and ignore subdirectories of subdirectories?

I am already familiar with grep -r "searchTerm" .我已经熟悉grep -r "searchTerm" . and I am familiar with grep -r "searchTerm" exclude={subdir1, subdir2} .我熟悉grep -r "searchTerm" exclude={subdir1, subdir2} . However, I am looking for a way to grep recursively, through subdirectories and ignore certain subdirectories of subdirectories.但是,我正在寻找一种通过子目录递归 grep 并忽略子目录的某些子目录的方法。

For example, if the directory structure is as follows:例如,如果目录结构如下:

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

How would I be able to exclude idc and otherStuffIdc, since these folders are subdirectories of subdirectories of the root directory I am beginning my search in?我如何能够排除 idc 和 otherStuffIdc,因为这些文件夹是我开始搜索的根目录的子目录的子目录?

My example is simplified but in my real world issue, there are many, many subDir# so it is not feasible for me to just grep each individual subdirectory.我的例子被简化了,但在我的现实世界问题中,有很多很多subDir#所以我只对每个单独的子目录进行 grep 是不可行的。

这将排除名称为idcotherStuffIdc的(子)目录。

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何递归grep所有目录和子目录? - How do I recursively grep all directories and subdirectories? 如何在Linux中递归重命名目录和子目录? - How to rename directory and subdirectories recursively in linux? 递归查找子目录和文件 - Recursively find subdirectories and files 如何修复此 Bash 函数以从指定路径开始并递归列出其子目录和这些子目录等 - How can I fix this Bash function to start at a specified path and recursively list its subdirectories and the subdirectories of those etc 如何递归查找并列出具有子目录和时间的目录中的最新修改文件 - How to recursively find and list the latest modified files in a directory with subdirectories and times 如何在 C 中使用 scandir() 递归地列出排序的子目录 - How to use scandir() in C to list sorted subdirectories recursively 使用grep在子目录中递归搜索特定文件名内的特定关键字 - Using grep to recursively search through subdirectories for specific keyword inside specific filename git-“忽略”或避免版本控制子目录 - git - “ignore” or avoid versioning subdirectories 在Linux C中枚举目录条目时如何忽略子目录 - How to ignore subdirectories when enumerating directory entries in linux C 递归重命名所有子目录中的 .jpg 文件 - Recursively rename .jpg files in all subdirectories
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM