如何找出当前目录中不包含单词foo(使用grep)的文件?


当前回答

为了完整,ripgrep版本如下:

rg --files-without-match "pattern"

你可以结合文件类型和搜索路径,例如:

rg --files-without-match -t ruby "frozen_string_literal: true" app/

其他回答

你实际上需要:

find .  -not  -ipath '.*svn*' -exec  grep  -H -E -o -c  "foo"  {} \; | grep :0\$
grep -irnw "filepath" -ve "pattern"

or

grep -ve "pattern" < file

上面的命令会给我们结果,因为-v找到了正在搜索的模式的倒数

如果你的grep有-L(或——files-without-match)选项:

$ grep -L "foo" *

为了完整,ripgrep版本如下:

rg --files-without-match "pattern"

你可以结合文件类型和搜索路径,例如:

rg --files-without-match -t ruby "frozen_string_literal: true" app/

来看看ack。它自动为您排除.svn,为您提供Perl正则表达式,并且是一个简单的Perl程序下载。

在ack中,与你要找的内容等价:

ack -L foo