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"
Written by Filippo Valsorda
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#