First, to do this with find you would add a second -exec
argument. Each argument is only able to run one command. If you needed to run multiple things you would have to use a hack by making the one command a shell and running multiple commands. Here it is with find
doing the work:
find . -name "*.xml" -exec grep -qi "keyword1" {} \; -exec grep -qi "keyword2" {} \; -print
Note that I have used finds -print
option to output the files names instead of having grep do it and used the -q
option of grep to put it in silent mode so that it simply gives a return code that can be used by find to tell if the result was true or not, then move on. If it reaches the last step (meaning both files have matched) it prints the output.
However this is inefficient because grep is actually having to scan all the files twice. If you meant your question literally this will have to do, but if you meant to find files containing ANY of the strings you can use grep to search for both patterns on one pass like this:
find . -name "*.xml" -exec grep -qi -e "keyword1" -e "keyword2" {} \; -print
Edit: It is unclear in your question what exactly you want to have happen, and the two examples I gave actually do different things. The first one is an AND operation and only prints files that contain both keywords and the second is an OR operation that prints the file name if it contains either string. Pick your poison.