find -exec cmd {} + vs | xargs [英] find -exec cmd {} + vs | xargs
问题描述
哪一个比一组非常大的文件更有效,应该使用?
find。 -exec cmd {} +
或
find。 | xargs cmd
(假设文件名中没有有趣的字符)
$ b $但是你必须确保:
>-
您的脚本不会假设
文件在
文件名中没有空格, -
您的脚本不会处理以
开头的文件 -
因此,您的代码应如下所示:
查找。 -exec cmd -option1 -option2 - {} +
或
查找。 -print0 | xargs -0 cmd -option1 -option2 -
第一个版本更短,可以忽略1,但是
第二个版本更加可移植和安全,因为 -exec cmd {} +
是一个相对较新的选项在GNU findutils 2005,很多运行系统将没有它),最近是越野车。也有很多人不知道这个 -exec cmd {} +
,你可以从其他答案看到。
Which one is more efficient over a very large set of files and should be used?
find . -exec cmd {} +
or
find . | xargs cmd
(Assume that there are no funny characters in the filenames)
Speed difference will be insignificant.
But you have to make sure that:
Your script will not assume that no file will have no space, tab, etc in file name; the first version is safe, the second is not.
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.
这篇关于find -exec cmd {} + vs | xargs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!