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


当前回答

我的grep没有任何-L选项。我确实找到了解决办法。

这些想法是:

将包含相应字符串的所有文件名转储到txt1.txt。 将目录中的所有文件名转储到txt2.txt文件中。 使用diff命令区分2个转储文件。 Grep 'foo' *.log | cut -c1-14 | uniq > txt1.txt Grep * *.log | cut -c1-14 | uniq > txt2.txt Diff txt1.txt txt2.txt | grep ">"

其他回答

你实际上需要:

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

我运气很好

grep -H -E -o -c "foo" */*/*.ext | grep ext:0

我用grep -v的尝试只是给了我所有没有“foo”的行。

下面的命令给出了所有不包含foo模式的文件:

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" *