//View Tip #147
Similar Tips
» Highlight Grepped Text
» Replace expr by other recursively
» another solution to #67
» Bash terminal size
» Version all unversioned files in an SVN checkout


Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Find all files with given name (you can use Bash expansion if you'd like), and Grep for a phrase:
find . -name  -exec grep "phrase" {} \;

To display the filename that contained a match, use -print:
find . -name  -exec grep "phrase" {} \; -print

Or, use Grep options to print the filename and line number for each match:
find . -name  -exec grep -Hn "phrase" {} \;

The string `{}` is replaced by the current filename being processed everywhere it occurs in the arguments to the command. See the `find` man page for more information.

View Comments »


Add your comment

Comments are currently disabled
ur doin it wrong!

grep -R "phrase" ./mydir/*.txt

it's this way only
Posted 2010-08-25 23:37:25
Also check out ack

Posted 2010-09-06 22:15:54

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit