[SOLVED] Find files containing multiple strings

Issue

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

Answered By – Mustafa DOGRU

Answer Checked By – Terry (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *