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

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

问题描述

我有大量目录,我试图计算数百个 .txt 文件的总大小.我试过这个,它最有效:

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

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

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?

谢谢!亚历克斯

推荐答案

du 使用 --files0-from 选项怎么样?您必须适当地生成以 null 结尾的文件输出:

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 {}"" ; | du -hc --files0-from=-

在我的系统上正常工作.

works correctly on my system.

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

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