On Tue, Sep 26, 2000 at 10:26:04AM -0500, Dave Sherohman wrote:
> On Tue, Sep 26, 2000 at 09:30:36AM -0500, dopp at acm.cs.umn.edu wrote:
> > I think it would just be 
> > 
> > find . -type f | xargs grep pattern
> 
> If you're using find, is there ant advantage to using xargs instead of find
> handling the filenames itself?
> 
> find . -type f -exec grep pattern {} \;
> 
> (Well, OK...  I guess my version is a few more keystrokes...)
> 
Yes, using xargs in this case takes an itty-bitty fraction of the time it
takes to exec out of find.  The reason:

find . -type f -exec grep pattern {} \;  execs grep on _each_ file it finds,
individually, where as

find . -type f | xargs grep pattern  execs grep on all the files
collectively.  

You'd see something similar if you did find . -type f | xargs chmod 644 vs.
find . -type f -exec chmod 644 {} \;.  THe latter would take orders of
magnitude longer, while the former would happen in the blink of an eye.

Just try it.

Gabe

-- 
--------------------------------------------------------------------------------
Gabe Turner				       |  	   X-President,
UNIX Systems Administrator,		       | Assoc. for Computing Machinery
U of M Supercomputing Institute for	       |    Univerisity of Minnesota
Digital Simulation and Advanced Computation    |       dopp at acm.cs.umn.edu

"My dinosaur droppings!  Painted like Easter eggs!"
						- Ren Hoek in "Sven Hoek"
--------------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: tclug-list-unsubscribe at mn-linux.org
For additional commands, e-mail: tclug-list-help at mn-linux.org