【问题标题】:How to find the files recursively having a text pattern excluding some directories and files [duplicate]如何递归地查找具有文本模式的文件,不包括某些目录和文件[重复]
【发布时间】:2018-01-11 23:07:52
【问题描述】:

如何递归查找具有文本模式但不包括某些目录和文件的文件?

Example:- 
$ ls
bower.json      bower_components    configure       results         unit-tests

所以我需要在除 bower.json 和 results 之外的所有目录中递归查找“searchText”

【问题讨论】:

  • 使用stackoverflow.com/q/4210042/798223 中的方法,然后使用 -exec 标志对这些文件进行 grep。
  • 您能提供确切的命令吗?这是行不通的。 find -name "*.js" -not -path 结果
  • find -type f -not -path './bower.json' -not -path './results/*' -exec grep 'searchString' -- '{}' +,但@RomanPerekhrest 的回答更好。
  • 我也标记了这个问题,因为最初我将它标记为错误内容的副本,希望很快会得到修复。
  • 感谢 GKFX!。我什至发现 grep 解决方案更好更干净。

标签: bash shell sh


【解决方案1】:

grep解决方案:

grep -r --exclude="bower.json" --exclude-dir="results" "searchText"

【讨论】:

  • 感谢它的工作。只是一件小事。你需要把点(。)放在最后。 grep -r --exclude="bower.json" --exclude-dir="results" "reset-device" .
  • @nagendra547,欢迎,点 . 是默认的
猜你喜欢
  • 2011-12-22
  • 2013-06-11
  • 1970-01-01
  • 2015-11-15
  • 2013-10-10
  • 2012-11-06
  • 2012-09-24
  • 2013-02-13
  • 2013-04-22
相关资源
最近更新 更多