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


当前回答

find *20161109* -mtime -2|grep -vwE "(触发器)"

你可以在"find"下指定过滤器,在"grep -vwE"下指定排除字符串。如果你也需要对修改后的时间进行过滤,请在find下使用mtime。

其他回答

find *20161109* -mtime -2|grep -vwE "(触发器)"

你可以在"find"下指定过滤器,在"grep -vwE"下指定排除字符串。如果你也需要对修改后的时间进行过滤,请在find下使用mtime。

你实际上需要:

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

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

$ grep -L "foo" *

这可能会对其他人有所帮助。我有混合文件Go和测试文件。但我只需要。go文件。所以我用了

ls *.go | grep -v "_test.go"

-v,——invert-match选择不匹配的行参见https://stackoverflow.com/a/3548465

也可以使用vscode从终端打开所有文件

code $(ls *.go | grep -v "_test.go")

当grep没有-L选项时(例如IBM AIX),只有grep和shell时的另一种选择:

for file in * ; do grep -q 'my_pattern' $file || echo $file ; done