[Novalug] bash commands
Richard Rognlie
rrognlie at gamerz.net
Fri Jan 18 15:44:57 EST 2008
On Fri, Jan 18, 2008 at 03:28:03PM -0500, dtidrow at patriot.net wrote:
> > Some systems have rgrep, but in the absense of that...
> >
> > cd WHEREVER
> >
> > then either
> > find . -name \*.f -print0 | xargs -0 grep 'string' /dev/null
> >
> Generally I do it this way:
> find . -name \*.f -exec grep 'string' {} \;
>
> The above comand runs grep on every file found - the '{}' supplies the
> filename to grep, and the '\;' tells -exec where the command ends
Two minor complaints about that invocation...
1. grep would always be invoked with 1 filename. And therefore never show
you which file actually matched. Just the matching lines themselves.
find . -name \*.f -exec grep 'string' /dev/null {} \;
fixes that.
2. grep is invoked once for each file that matches the pattern.
using xargs limits the number of invocations by calling grep with a
bunch of files each time. minor overhead gain.
--
/ \__ | Richard Rognlie / Sendmail Ninja / Gamerz.NET Lackey
\__/ \ | http://www.gamerz.net/~rrognlie <rrognlie at gamerz.net>
/ \__/ | Creator of pbmserv at gamerz.net
\__/ | Helping reduce world productivity since 1994
More information about the Novalug
mailing list