grep如何排除子目录

grep如何排除子目录,grep,Grep,我使用grep查找字符串,我想用grep-rl--exclude dir=application/res--color'super'排除一个目录,但它也会在目录application/res/下显示match 当我使用grep-rl--exclude dir=application--color'super'时,在application路径下没有匹配项 如何在使用grep时排除一个子目录 grep版本: $ grep -V grep (GNU grep) 2.20 -r, --recurs

我使用grep查找字符串,我想用
grep-rl--exclude dir=application/res--color'super'
排除一个目录,但它也会在目录
application/res/
下显示match

当我使用
grep-rl--exclude dir=application--color'super'
时,在
application
路径下没有匹配项

如何在使用grep时排除一个子目录

grep版本:

$ grep -V
grep (GNU grep) 2.20
  -r, --recursive           like --directories=recurse
  -R, --dereference-recursive
                            likewise, but follow all symlinks
      --include=FILE_PATTERN
                            search only files that match FILE_PATTERN
      --exclude=FILE_PATTERN
                            skip files and directories matching FILE_PATTERN
      --exclude-from=FILE   skip files matching any file pattern from FILE
      --exclude-dir=PATTERN directories that match PATTERN will be skipped.
grep帮助:

$ grep -V
grep (GNU grep) 2.20
  -r, --recursive           like --directories=recurse
  -R, --dereference-recursive
                            likewise, but follow all symlinks
      --include=FILE_PATTERN
                            search only files that match FILE_PATTERN
      --exclude=FILE_PATTERN
                            skip files and directories matching FILE_PATTERN
      --exclude-from=FILE   skip files matching any file pattern from FILE
      --exclude-dir=PATTERN directories that match PATTERN will be skipped.

使用“查找”可以排除带有斜杠的整个路径:

find . -path ./application/res -prune -o -type f -exec grep -l super {} +

尽管更便于携带,但这将比
grep-r
慢。但就我而言,GNU grep并没有提供排除路径的机制。

因为它只匹配basename,所以就我所知,任何
/
都是无用的<代码>递归搜索时,跳过基名称与glob匹配的任何子目录。忽略glob中任何多余的尾部斜杠。如果您对其他应用程序没有问题,可以使用。。。例如:
rg-g='!application/res/'
或者,使用
find-type f-not-path'./application/res/*'-exec grep-l'super'{}+
@Sundeep仍然在/application/res下处理文件/dir,但不向grep传递任何内容,即:这是对find@oguzismail我不知道情况是否如此,但还有什么选择呢?