How can I search for text files that do NOT contain a word?

8,147

tl:dr:

grep -rIL searchword

According to the Manual:

-R, -r, --recursive

Read all files under each directory, recursively; this is equivalent to the -d recurse option.

-L, --files-without-match

Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.

-I

Process a binary file as if it did not contain matching data; this is equivalent to the --binary-files=without-match option.

Share:
8,147

Related videos on Youtube

Dan M
Author by

Dan M

Updated on September 18, 2022

Comments

  • Dan M
    Dan M over 1 year

    I need to be able to search a directory for all files that do not contain a certain word. My issue with my approaches so far is that they return every line of every file that does not contain the word. I just need a list of files that don't contain it.

    Is there a program that does this? I prefer windows, but I also can use linux commands if you have one. I thought about grep -v, but this ends up printing out every lien of every file in a large directory (since most lines do not contain the phrase). I just need the file names (but contents searched).

    Suggestions?

  • Dan M
    Dan M about 8 years
    Thank you, this does the trick. I had to do a more complicated command, but -L is the magic here.