I love the '-exec' flag for find
It is much, much faster to pipe commands to "xargs". For instance:
find . -name core -print0 | xargs -0 rm -f
Since "find" doesn't know when your command is multi-file, it has to run the command once per file; whereas, "xargs" can run it as few times as necessary. It works well for any command that accepts "a list of files".In the example above, the -print0/-0 are a safety net to null-delimit filenames so that it doesn't matter if any of the paths contains a space.
$ find . -name 'blah*' |wc -l
2000
$ find . -name 'blah*' |xargs -n 250 -P 8 ./mangle
That'll spawn 8 copies of mangle, each with 250 blah files on its command line.If I want this I have the choice between: '-exec sed -i s/a/b/g {} \;' in find or '| xargs -IX sed -i s/a/b/g X'
Efficient because additional exec's are removed, for the most part find can perform the unlink itself. Safer because a replacement version for rm cannot be inserted into the user's path.
Before -delete was added to find I always found perl faster:
find2perl scratch -type f -size 0 -eval 'unlink' | perl
or find2perl scratch -type f -size 0 -exec rm {} \; | perl
The last case does not actually call rm but is hard-wired to use unlink().It may still be faster.