How to find text files not containing text on Linux?

eon picture eon · Aug 26, 2011 · Viewed 35.3k times · Source

How do I find files not containing some text on Linux? Basically I'm looking for the inverse of the following

find . -print | xargs grep -iL "somestring"

Answer

sehe picture sehe · Aug 26, 2011

The command you quote, ironically enough does exactly what you describe. Test it!

echo "hello" > a
echo "bye" > b
grep -iL BYE a b

Says a only.


I think you may be confusing -L and -l

find . -print | xargs grep -iL "somestring"

is the inverse of

find . -print | xargs grep -il "somestring"

By the way, consider

find . -print0 | xargs -0 grep -iL "somestring"

Or even

grep -IRiL "somestring" .