

There is a bit of a debate in some circles about using xargs vs. the -exec
{} option that’s built into find itself. To me, however, it’s not much of a
debate; -exec isn’t nearly as good as xargs for what I use find for. I tend
to use it to perform tasks involving many files. “Move all these files
there”, “copy all those directories there”, “Delete these links.”, etc.
That’s all nice and stuff, but you probably want to see it in action, right?
Let’s run some numbers. Below is a listing of 1,668 .jpg files on my OS X
system using both -exec and xargs:
time find . -name "*.jpg" -exec ls {} ;
real 0m6.618s user 0m1.465s sys 0m4.396s
Hmm, that’s not bad — seven seconds for over around 1,600 files, right?
Let’s try it with xargs.
# time find . -name "*.jpg" -print0 | xargs -0 ls real 0m1.120s user 0m0.594s sys 0m0.527s
That’s one (1) second vs seven (7) seconds. Seriously; xargs is the way to
go.
Related Posts

Technical Analysis: 4 Stocks with signs of death crossovers to keep an eye on

HDFC Bank & 3 other fundamentally strong stocks trading above 200 DMA to keep an eye on

Falling Channel Breakout: Multibagger NBFC Stock Shows Bullish Momentum on Daily Chart

4 Fundamentally strong stocks to buy for an upside potential of up to 36%; Do you hold any?

0 responses on "Effort vs. Outcome"