[PLUG] Recursive grep

Galen Seitz galens at seitzassoc.com
Mon Sep 23 20:31:32 UTC 2002


> > When I want to grep through (for example) all the .c files in
> > a hierarchy I've been using find, for example:
> > 
> >   find . -name \*.c -exec fgrep -H "find.this.string" {} \;
> > 
> > It SEEMS like I ought to be able to accomplish the same thing using
> > grep recursively, something like: 
> > 
> >   grep -r "find.this.string" *.c
> 
> No, because -r == -d recurse, so grep reads all files under each 
> directory that matches the '*.c' expansion.
> 
> find's -exec option is expensive, however, so you can do a hacky sort 
> of combination to speed things up a bit:
> 
>   grep 'find.this.string' $(find . -name \*.c)
> 

Is this better in some way than: 

  find . -name \*.c xargs grep 'find.this.string'

BTW, Mike, cscope and cygnus' source navigator are both freely available
now.

galen






More information about the PLUG mailing list