2 ms·
I thought find -exec was the preferred way of doing it (better with spaces, not limited in command line length, etc). Why would it be better to use xargs?
by losvedir 15y ago
I thought find -exec was the preferred way of doing it (better with spaces, not limited in command line length, etc). Why would it be better to use xargs?
- michaelcampbell 15y agoWith gnu tools, at least, xargs has a "-0" option to go hand in hand with gnu find's "-print0" option which obviates the spaces problem. xargs is "better" in that it spawns 1 new process for however many things are found. -exec spawns 1 new process for EVERY thing found. So: find . -name '*.log' -exec rm {} \; spawns an rm for every log file. find . -name '*.log' -print0 | xargs -0 rm spawns 1 rm for MANY log files. (Yes, I know zsh can do stuff like this too.) xargs also has options to limit command line length or # of items if you want to limit that. find -exec is about the same then as find ... | xargs -n1