stringunixsearchgrepfind

Find files containing multiple strings


I use a command to recursively find files containing a certain string1:

find . -type f -exec grep -H string1 {} \;

I need to find files containing multiple strings, so the command should return those containing all strings. Something like this:

find . -type f -exec grep -H string1 AND string2 {} \;

I couldn't find a way. The strings can be anywhere in the files. Even a solution for only two strings would be nice.


Solution

  • you can also try this;

    find . -type f -exec grep -l 'string1' {} \; | xargs grep -l 'string2'
    

    this shows file names that contain string1 and string2