如何使用 find 和 du 获取文件夹的总大小? [英] How to get total size of folders with find and du?

查看:17
本文介绍了如何使用 find 和 du 获取文件夹的总大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 find 和 du 获取名为bak"的目录的大小.

I'm trying to get the size of the directories named "bak" with find and du.

我这样做:find -name bak -type d -exec du -ch '{}' ;

但它返回每个名为bak"的文件夹的大小而不是总数.

But it returns the size for each folder named "bak" not the total.

无论如何要得到它们?谢谢:)

Anyway to get them ? Thanks :)

推荐答案

使用xargs(1) 而不是 -exec:

find . -name bak -type d | xargs du -ch

-exec 为找到的每个文件执行命令(检查 find(1) 文档).通过管道连接到 xargs 可以聚合这些文件名并且只运行一次 du.你也可以这样做:

-exec executes the command for each file found (check the find(1) documentation). Piping to xargs lets you aggregate those filenames and only run du once. You could also do:

find -name bak -type d -exec du -ch '{}' ; +

如果您的 find 版本支持它.

If your version of find supports it.

这篇关于如何使用 find 和 du 获取文件夹的总大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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