为什么“查找”。 -name * .txt | xargs du -hc“给多个总数? [英] Why does "find . -name *.txt | xargs du -hc" give multiple totals?

查看:214
本文介绍了为什么“查找”。 -name * .txt | xargs du -hc“给多个总数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一大组目录,我试图计算几百个.txt文件的总大小。我试过这个,主要工作:

  find。 -name * .txt | xargs du -hc 

但是最后我没有给我一个总数,我得到了几个。我的猜测是管道一次只能传递很多find的输出行,而du只是在每个批次上运行。有没有办法解决这个问题?



谢谢!
Alex

解决方案

如何使用--files0-from选项到du?您必须相应地生成以null结尾的文件输出:

  find。 -name* txt-exec echo -n -e {}\0\; | du -hc --files0-from =  -  

在我的系统上正常工作。


I have a large set of directories for which I'm trying to calculate the sum total size of several hundred .txt files. I tried this, which mostly works:

find . -name *.txt | xargs du -hc

But instead of giving me one total at the end, I get several. My guess is that the pipe will only pass on so many lines of find's output at a time, and du just operates on each batch as it comes. Is there a way around this?

Thanks! Alex

解决方案

How about using the --files0-from option to du? You'd have to generate the null-terminated file output appropriately:

find . -name "*txt" -exec echo -n -e {}"\0" \; | du -hc --files0-from=-

works correctly on my system.

这篇关于为什么“查找”。 -name * .txt | xargs du -hc“给多个总数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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