find a file

Smoot Carl-Mitchell smoot at tic.com
Mon Aug 6 18:28:19 UTC 2007


On Mon, 2007-08-06 at 22:42 +1000, Karl Auer wrote:
> On Mon, 2007-08-06 at 08:21 -0300, Allan Valeriano wrote:
> 

>    find . -name "*.txt" -exec grep help {} \; -print

Slightly easier syntax is:

find . -name "*.txt" -exec grep -H help {} \;

The -H switch prints the filename on each matching line in each file.
You normally do not need this, since grep's default is to print the
filename if there is more than a single file in the argument list.

Or if you want to avoid find altogether you can do something like this:

grep -r --include="*.txt" help .

You need the quotes around the *.txt or otherwise the shell will expand
the "*" before it is passed to grep.

See the grep manual page for all the gory details.
-- 
Smoot Carl-Mitchell
System/Network Architect
email: smoot at tic.com
cell: +1 602 421 9005
home: +1 480 922 7313




More information about the ubuntu-users mailing list