find -exec cmd {} + vs | xargs [英] find -exec cmd {} + vs | xargs

查看:153
本文介绍了find -exec cmd {} + vs | xargs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪一个比一组非常大的文件更有效,应该使用?

  find。 -exec cmd {} + 

  find。 | xargs cmd 

(假设文件名中没有有趣的字符)

$ b $



但是你必须确保:

>


  1. 您的脚本不会假设
    文件在
    文件名中没有空格,


  2. 您的脚本不会处理以开头的文件 -


因此,您的代码应如下所示:

 查找。 -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:

  1. 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.

  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.

这篇关于find -exec cmd {} + vs | xargs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆