哪一个对一组非常大的文件更有效,应该使用?
find . -exec cmd {} +
或
find . | xargs cmd
(假设文件名中没有有趣的字符)
哪一个对一组非常大的文件更有效,应该使用?
find . -exec cmd {} +
或
find . | xargs cmd
(假设文件名中没有有趣的字符)
速度差将是微不足道的.
但你必须确保:
你的脚本不会假设没有
脚本不会将以"-
"开头的文件视为选项.
所以你的代码应该是这样的:
find . -exec cmd -option1 -option2 -- {} +
或
find . -print0 | xargs -0 cmd -option1 -option2 --
The first version is sh或ter and easier to write as you can ign或e 1, but
the second version is m或e p或table 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.