在Unix shell上加一列数字 [英] Add up a column of numbers at the Unix shell

查看:144
本文介绍了在Unix shell上加一列数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出files.txt中的文件列表,我可以得到它们的大小列表,如下所示:

Given a list of files in files.txt, I can get a list of their sizes like this:

cat files.txt | xargs ls -l | cut -c 23-30

产生类似这样的东西:

  151552
  319488
 1536000
  225280

如何获得所有这些数字的总数?

How can I get the total of all those numbers?

推荐答案

... | paste -sd+ - | bc

是我找到的最短的一个(从 UNIX命令线博客).

is the shortest one I've found (from the UNIX Command Line blog).

编辑:感谢@Dogbert和@Owen,为可移植性添加了-参数.

added the - argument for portability, thanks @Dogbert and @Owen.

这篇关于在Unix shell上加一列数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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