How to grep a string in a directory and all its subdirectories?

Rogers picture Rogers · Mar 25, 2013 · Viewed 593.2k times · Source

How to grep a string or a text in a directory and all its subdirectories'files in LINUX ??

Answer

John Kugelman picture John Kugelman · Mar 25, 2013

If your grep supports -R, do:

grep -R 'string' dir/

If not, then use find:

find dir/ -type f -exec grep -H 'string' {} +