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


当前回答

你实际上需要:

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

其他回答

如果你正在使用git,它会搜索所有被跟踪的文件:

git grep -L "foo"

如果你打开了**子目录globbing,你可以在跟踪文件的子集中搜索(在.bashrc中使用shopt -s globstar):

git grep -L "foo" -- **/*.cpp

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

$ grep -L "foo" *

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

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

下面的命令不需要find通过使用第二个grep来过滤svn文件夹。

grep -rL "foo" ./* | grep -v "\.svn"
grep -irnw "filepath" -ve "pattern"

or

grep -ve "pattern" < file

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