//View Tip #147
Similar Tips
» Randomize lines in a file
» Duplicate directory tree
» Tar remote dir over SSH
» ESC-g for glob expansion in bash
» Loop over files with spaces in the name

 

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 »




Comments 

Add your comment

Comments are currently disabled
dekkard
ur doin it wrong!

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

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

http://betterthangrep.com/
Posted 2010-09-06 22:15:54

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit