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

后端 未结 16 1305
半阙折子戏
半阙折子戏 2020-11-28 17:42

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

16条回答
  •  日久生厌
    2020-11-28 18:13

    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
    

提交回复
热议问题