To find the files that contain a string we can use:
find . -exec grep -l “string to find” {} \;
This starts the search from the current directory, looks for files that contain the specified string, and then it prints their names.
To find the files that contain a string we can use:
find . -exec grep -l “string to find” {} \;
This starts the search from the current directory, looks for files that contain the specified string, and then it prints their names.
July 30, 2006 at 11:32 pm |
If you also want to print an excerpt of the matched text, change the command to:
find . -exec grep -H “string to find” {} \;
In both cases, for faster results (does not spawn multiple grep instances), reverse grep with find like this:
grep -l “string to find” `find .`
or
grep -H “string to find” `find .`
July 25, 2008 at 12:15 pm |
great, most helpful!
March 18, 2009 at 12:13 am |
thanks dude!
March 18, 2009 at 12:43 am |
I’ve been liking the original better:
find . -exec grep -l “string to find” {} \;
I tend to get an error that says “Argument List Too Long” when I use Radu’s.