猫/ xargs的/命令为VS /庆典/命令 [英] cat/Xargs/command VS for/bash/command

查看:136
本文介绍了猫/ xargs的/命令为VS /庆典/命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这本书的Linux黑客101的第38页显示:

The page 38 of the book Linux 101 Hacks suggests:

cat url-list.txt | xargs wget –c

我通常做的:

for i in `cat url-list.txt`
   do
      wget -c $i
   done

有一些事,莫过于长,其他地方的xargs-技术优于老的好 - 环 - 技术在bash?

Is there some thing, other than length, where the xargs-technique is superior to the old good for-loop-technique in bash?

添加

的的 C源$ C ​​$ C 好像只有一个叉。相比之下,多少叉有与bash组合?请,阐述这一问题。

The C source code seems to have only one fork. In contrast, how many forks have the bash-combo? Please, elaborate on the issue.

推荐答案

从的在UNIX联机帮助页的xargs 。 (有趣的是这一节不会出现在的xargs 的OS X版本的BSD,也不在GNU版本)。

From the Rationale section of a UNIX manpage for xargs. (Interestingly this section doesn't appear in the OS X BSD version of xargs, nor in the GNU version.)

在xargs的的典型应用
  实用程序是在与结合
  找到工具来减少数量
  通过一个简单的使用启动的进程
  的发现-exec组合。该
  xargs的效用还用于执行
  内存上限要求
  启动一个进程。随着此基础上
  没关系,这个量POSIX.1-2008的
  只选择了最小的功能
  必需的。

The classic application of the xargs utility is in conjunction with the find utility to reduce the number of processes launched by a simplistic use of the find -exec combination. The xargs utility is also used to enforce an upper limit on memory required to launch a process. With this basis in mind, this volume of POSIX.1-2008 selected only the minimal features required.

在您的随访中,你问另一个版本将会有多少叉有。 <一href=\"http://stackoverflow.com/questions/1282697/cat-xargs-command-vs-for-bash-command/1282713#1282713\">Jim已经回答了这个:在每次迭代之一。多少次迭代有哪些?这是不可能给出一个确切的数字,但容易回答一般问题。在您的网址,LIST.TXT文件有多少行有哪些?

In your follow-up, you ask how many forks the other version will have. Jim already answered this: one per iteration. How many iterations are there? It's impossible to give an exact number, but easy to answer the general question. How many lines are there in your url-list.txt file?

有其他一些其他考虑。 的xargs 需要格外小心与空格或其他无任何字符,而 -exec 文件名有一个选项( + ),这组加工成批次。所以,不是每个人都prefers 的xargs ,也许它不是最好的所有情况。

There are other some other considerations. xargs requires extra care for filenames with spaces or other no-no characters, and -exec has an option (+), that groups processing into batches. So, not everyone prefers xargs, and perhaps it's not best for all situations.

请参阅以下链接:

  • http://www.sunmanagers.org/pipermail/summaries/2005-March/006255.html
  • http://fahdshariff.blogspot.com/2009/05/find-exec-vs-xargs.html

这篇关于猫/ xargs的/命令为VS /庆典/命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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