logoalt Hacker News

em-beeyesterday at 11:19 PM2 repliesview on HN

why would you ever pipe find into xargs instead of calling -exec?

    find -exec the '{}' iterated command ';'

Replies

gumbyyesterday at 11:25 PM

Because xargs is faster. Exec will invoke the command once per matching file (which is sometimes what you want, of course)!

While xargs will accumulate a bunch of file names, then when it as n names will invoke the command with those names, while continuing to accumulate names until n is reached or the pipe closes.

The size of n depends on the system, but is usually at least a thousand.

show 2 replies
t-3yesterday at 11:49 PM

Leah Neukirchen's lr and xe are very nice as a find and xargs replacement (although lr's test flag is way too complex). lr *.file | xe -s ' ... ' is a really great pattern for iterative scripting and hard to get wrong.