Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find files that do not contain a given string pattern?

How do I find out the files in the current directory which do not contain the word foo (using grep)?

like image 667
Senthil Kumar Avatar asked Nov 17 '09 11:11

Senthil Kumar


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.

Which command searches a file or files that have a certain pattern?

The grep command searches through the file, looking for matches to the pattern specified. To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in. The output is the three lines in the file that contain the letters 'not'.

How do I find all files containing specific text?

If you'd like to always search within file contents for a specific folder, navigate to that folder in File Explorer and open the “Folder and Search Options.” On the “Search” tab, select the “Always search file names and contents” option.


2 Answers

If your grep has the -L (or --files-without-match) option:

$ grep -L "foo" * 
like image 51
ghostdog74 Avatar answered Oct 15 '22 11:10

ghostdog74


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

grep -riL "foo" . 

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 (lowercased) you will get the opposite (files with matches)

     -l, --files-with-matches              Only the names of files containing selected lines are written 
like image 29
Adrian Avatar answered Oct 15 '22 13:10

Adrian