How do I grep recursively?

wpiri picture wpiri · Jan 1, 2010 · Viewed 1.6M times · Source

How do I recursively grep all directories and subdirectories?

find . | xargs grep "texthere" *

Answer

Vinko Vrsalovic picture Vinko Vrsalovic · Jan 1, 2010
grep -r "texthere" .

The first parameter represents the regular expression to search for, while the second one represents the directory that should be searched. In this case, . means the current directory.

Note: This works for GNU grep, and on some platforms like Solaris you must specifically use GNU grep as opposed to legacy implementation. For Solaris this is the ggrep command.