Last Updated: February 25, 2016
·
1.707K
· filosottile

grep a directory recursively

Sometimes you need to find all occurrences of some code across your codebase, or you can't remember where some string is.

Then, using grep in recursive mode can come handy (in my example, I am changing a URL and I want to find all its occurrences):

grep -rn "/blog/archives"

(-n added to get line numbers)

However, not all grep implementations support -r, so here is an elegant way to do it with find:

find . -type f -print0 | xargs -0 grep -n "/blog/archives"