加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

cat / Xargs /命令VS for / bash / command

发布时间:2020-12-15 22:28:36 所属栏目:安全 来源:网络整理
导读:Linux 101 Hacks一书的第38页建议: cat url-list.txt | xargs wget –c 我经常这样做: for i in `cat url-list.txt` do wget -c $i done 有什么东西,除了长度,xargs技术在bash中优于旧的for-loop-technique? 添加 C source code似乎只有一个叉子.相比之下
Linux 101 Hacks一书的第38页建议:

cat url-list.txt | xargs wget –c

我经常这样做:

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

有什么东西,除了长度,xargs技术在bash中优于旧的for-loop-technique?

添加

C source code似乎只有一个叉子.相比之下,有多少叉子有bash-combo?请详细说明这个问题.

解决方法

从 a UNIX manpage for xargs的Rationale部分开始.(有趣的是,这部分没有出现在OS X的BS X版本中,也没有出现在GNU版本中.)

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.

在您的后续行动中,您会询问其他版本的叉子数量. Jim already answered this:每次迭代一次.有多少次迭代?提供一个确切的数字是不可能的,但很容易回答一般问题.你的url-list.txt文件中有多少行?

还有其他一些考虑因素. xargs需要额外注意带有空格或其他禁止字符的文件名,-exec有一个选项(),它将处理分组为批处理.所以,并不是每个人都喜欢xargs,也许并不是所有情况都是最好的.

看到这些链接:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读