find -exec cmd {} + vs | xargs

Speed difference will be insignificant.

But you have to make sure that:

  1. Your script will not assume that no
    file will have space, tab, etc in
    file name; the first version is
    safe, the second is not.

  2. Your script will not treat a file starting with “-” as an option.

So your code should look like this:

find . -exec cmd -option1 -option2 -- {} +

or

find . -print0 | xargs -0 cmd -option1 -option2 --

The first version is shorter and easier to write as you can ignore 1, but
the second version is more portable and safe, as “-exec cmd {} +” is a relatively new option in GNU findutils (since 2005, lots of running systems will not have it yet) and it was buggy recently. Also lots of people do not know this “-exec cmd {} +“, as you can see from other answers.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)