Bash Party: RIP exec inside find

I use find too frequently to search for things, and most often, spawn some external command using -exec to process the results individually. This ars article gave a pretty neat idea to speed up find/exec to order of 10+ times; the technique uses xargs to remove the execution loop.

This is a sample run from my Ubuntu box:

$ time find . -name '*.properties' -exec wc -l {} \; -print
...
real    0m1.788s
user    0m0.096s
sys    0m0.120s

$ time find . -name '*.properties' -print0 | xargs -0 wc -l
 ...
real    0m0.169s
user    0m0.044s
sys    0m0.096s

Whoa!

About forrestrunning
Code Chaser

Leave a comment