Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find text files not containing text on Linux?

People also ask

How do I find all files not containing specific text on Linux?

You can do it with grep alone (without find). grep -riL "somestring" . -L, --files-without-match each file processed. -R, -r, --recursive Recursively search subdirectories listed.

How do you find files that do not contain a string?

You want to use the "-L" option of grep : -L, --files-without-match Only the names of files not containing selected lines are written to standard output. Path- names are listed once per file searched. If the standard input is searched, the string ``(standard input)'' is written.

How do I find all files containing specific text?

Without a doubt, grep is the best command to search a file (or files) for a specific text. By default, it returns all the lines of a file that contain a certain string. This behavior can be changed with the -l option, which instructs grep to only return the file names that contain the specified text.


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

You can do it with grep alone (without find).

grep -riL "somestring" .

This is the explanation of the parameters used on grep

     -L, --files-without-match
             each file processed.
     -R, -r, --recursive
             Recursively search subdirectories listed.

     -i, --ignore-case
             Perform case insensitive matching.

If you use l lowercase you will get the opposite (files with matches)

     -l, --files-with-matches
             Only the names of files containing selected lines are written