Using find with grep to find strings in files

Here is how to find files containing a certain string. This works in any system supporting Unix commands, including OSX.

find . -name '*.xml' -exec grep 'string to find' {} \;

Sometimes the files have no line breaks, so you just want to see the filename of the matches. Then you need the -l parameter.

find . -name '*.xml' -exec grep -l 'string to find' {} \;

Publicerat av Lukas Mattsson

Yogi and developer