How do I find out the files in the current directory which do not contain the word foo
(using grep
)?
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.
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'.
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.
If your grep has the -L
(or --files-without-match
) option:
$ grep -L "foo" *
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With