Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jan 1996 10:34:44 -0700 (MST)
From:      Terry Lambert <terry@lambert.org>
To:        jmacd@CS.Berkeley.EDU (Josh MacDonald)
Cc:        imp@village.org, wosch@cs.tu-berlin.de, hackers@FreeBSD.org
Subject:   Re: recursive grep
Message-ID:  <199601231734.KAA17822@phaeton.artisoft.com>
In-Reply-To: <199601230131.RAA11361@paris.CS.Berkeley.EDU> from "Josh MacDonald" at Jan 22, 96 05:31:37 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> > : I would like add options for recursive searching 
> > : (grep -R foo /usr/include). 
> > 
> > find /usr/local | xargs grep foo
> > 
> > Why do we need another wart on grep?  Especially when what you may
> > want is find /usr/local -name \*f.h | xargs grep foo :-)
> 
> and why do we need an extra pipe, either?
> 
> 	find /usr/include -name \*f.h -exec grep foo {} /dev/null \;

The GNU derived find doesn't flush its output, so if you were to pipe
it at that point (and use -print instead of a "/dev/null" argument to
get the name), you would have your output screwed.

The use of xargs causes one invocation of grep for a potentially
large number of files, once per command line length limit, so it
will execute it several times for an obscene number of files.

Typically, you *will* want to use the "/dev/null" trick to get grep
to spit out the name in case the last exec by xargs is on one file
(otherwise the last one will be missing its file name).

So:

	find /usr/local - print | xargs grep foo /dev/null

...use of -print is suggested in case of some older "finds" that do
not put out anything by default (POSIX compliance discrepancy).


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199601231734.KAA17822>