Andrew_1510
Andrew_1510

Reputation: 13526

linux command line: du --- how to make it show only total for each directories

I am doing it by (with coreutils_8.5-1ubuntu6_amd64):

du -sch `find ./ -maxdepth 1 -type d`

I am looking for a simple way (shorter cmd) to find size of subdirectories. Thank you.

Upvotes: 140

Views: 187663

Answers (8)

Pat. ANDRIA
Pat. ANDRIA

Reputation: 2412

Assuming that you have the following treeview:

/folder/202206

in which we would have the list of folders

|-- 20220601
|-- 20220602
|-- 20220603
|-- 20220604
|-- 20220605
`-- 20220606

If I understand your question, you would like to have shown only the total for each folder called 20220601...20220606

With the same idea as the response of Albert Veli, you enter the folder which contains all the sub-folders you would like to have the size of.

In this use case, you enter:

cd /folder/202206 

and retrieve the size of each of the sub-folders only

du -h -d 0 *

The option -h is "human readable"; -d is the depth to display and then to show only the size of subfolder, you choose -d 0

Another option would be to replace the -d 0with a -s (which means summarize) and it would give the same result.

The output would be like below

677M    20220601
693M    20220602
781M    20220603
630M    20220604
616M    20220605
713M    20220606

If you need to have a grand total, you could replace the -hwith -hc but this is not the question.

Upvotes: 0

babak khaksari
babak khaksari

Reputation: 209

This command is your answer:

du -sh *

Upvotes: 19

Zorro
Zorro

Reputation: 1519

All these answers didn't work for me, I think some parameters depend on the environment.

So I did this:

du -csh /home/pi/walala/* | grep total | sed 's/ *\stotal* *\(.*\)/\1/'

OR for bytes

du -csb /home/pi/walala/* | grep total | sed 's/ *\stotal* *\(.*\)/\1/'

Upvotes: 1

AkaKaras
AkaKaras

Reputation: 102

actually you can try :

du -kh | cut -f1

Upvotes: 6

Silicomancer
Silicomancer

Reputation: 9166

The following did the job for me:

du -hs */

Without the trailing slash the output was not restricted to directories.

Upvotes: 27

shem
shem

Reputation: 4712

create an alias:

alias subs="du -sch `find ./ -maxdepth 1 -type d`"

and I thing 'subs' is much shorter.

Upvotes: 0

DanS
DanS

Reputation: 18463

This works with coreutils 5.97:

du -cksh *

Upvotes: 146

Albert Veli
Albert Veli

Reputation: 2109

On my version of du (from coreutils 8.14) this works:

du -h -d 1

-h is for human readable sizes.

Upvotes: 157

Related Questions