bash 使用 du 获取特定子目录的大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/11633339/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using du to get size of specific sub directories
提问by btongeorge
I'm trying to write a script to summarise a bunch of folders. So I have the following structure:
我正在尝试编写一个脚本来汇总一堆文件夹。所以我有以下结构:
monitor/abc_123 1G
monitor/abc_213 1G 
monitor/abc_111 2G
monitor/bbc_123 2.5G
What I need is to issue a command (using du I presume) to summarise the directories prefixed with "abc_"
我需要的是发出一个命令(使用 du 我假设)来汇总以“abc_”为前缀的目录
I've tried the following:
我尝试了以下方法:
du -sh abc*
... but this just gives me a summary for each folder. I need the script to generate the total size of all three directories in this example.
...但这只是给了我每个文件夹的摘要。在此示例中,我需要脚本来生成所有三个目录的总大小。
Thanks in advance
提前致谢
回答by bitmask
How about
怎么样
du -ch abc_* | tail -n 1
That should produce a grand total.
这应该产生一个总数。

