[PLUG] Recursive grep

Paul Heinlein heinlein at attbi.com
Mon Sep 23 20:16:31 UTC 2002


On Mon, 23 Sep 2002, Mike Witt wrote:

> 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)

--Paul Heinlein <heinlein at attbi.com>





More information about the PLUG mailing list