«

»

Jan
13

Grep through sub-directories

Often times you want to search for a string pattern in all the files under a directory and its sub-directories.

Simply run this:
find . | xargs grep whatever

For example:
find . -name "*.txt" | xargs grep for

Output:
/cygdrive/c
[sohel@laptop] $ cat temp/post.txt
Time for an Upgrade.
It's about that time where your PC needs an upgrade. There was nothing wrong with my existing setup, but I figured, hey why not?

/cygdrive/c
[sohel@laptop] $ find . -name "*.txt" | xargs grep for
temp/post.txt:Time for an Upgrade.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>