Which one is more efficient over a very large set of files and should be used?
find . -exec cmd {} +
or
find . | xargs cmd
find . | xargs cmd
is more efficient (it runs cmd
as few times as possible, unlike exec
, which runs cmd
once for each match). However, you will run into trouble if filenames contain spaces or funky characters.
The following is suggested to be used:
find . -print0 | xargs -0 cmd
this will work even if filenames contain funky characters (-print0
makes find
print NUL-terminated matches, -0
makes xargs
expect this format.)