Using du to get size of specific sub directories

btongeorge picture btongeorge · Jul 24, 2012 · Viewed 8.5k times · Source

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_"

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

Answer

bitmask picture bitmask · Jul 24, 2012

How about

du -ch abc_* | tail -n 1

That should produce a grand total.