To find all the files that contain "foo" in current folder, I use:
grep -r "foo" .
To find all the files that contain "bar" in current folder, I use:
grep -r "bar" .
But how to find all files that does not contain 'foo' and 'bar'?
greplinuxregex
To find all the files that contain "foo" in current folder, I use:
grep -r "foo" .
To find all the files that contain "bar" in current folder, I use:
grep -r "bar" .
But how to find all files that does not contain 'foo' and 'bar'?
Best Answer
To print lines that do not contain some string, you use the
-v
flag:This gives you all lines that do not contain
foo
orbar
.To print files that do not contain some string, you use the
-L
flag. To non-match several strings, you can use regular expressions with the-P
flag (there are several regex flags you can use):This prints a list of files that don't contain
foo
orbar
.Thanks to Anton Kovalenko for pointing this out.