How to find files that don't contain a given search string
I have a command that finds all the PDF files that contain the string "Font"
find /Users/me/PDFFiles/ -type f -name "*.pdf" -exec grep -H 'Font' '{}' ';'
How can I change this command such that it does the inverse? Finds all PDF files that do not contain the search string "Font"
Solution 1:
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.
Solution 2:
Just add the "L" flag. This does the inverse
find /Users/me/PDFFiles/ -type f -name "*.pdf" -exec grep -HL 'Font' '{}' ';'