Shell – Using grep after using find to get the files

findgreplinuxshell-script

So I'm relatively new to command line. I was able to use find to get an output of multiple files from multiple directories since there was no specific place these would be (I'm sure this can be shortened):

find ./ -name filename1.ext && find ./ -name filename2.ext && find ./ -name filename3.ext

Now that gave me the list of what I was wanting but now that I've found the files in question, I want to grep them for information.

Best Answer

You can group all the name primaries in a single find statement then have find execute grep.

find . \( -name filename1.ext -o \
      -name filename2.ext -o \
      -name filename3.ext \) \
      -exec grep 'pattern' {} \;
Related Question