Reputation: 13526
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
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 0
with 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 -h
with -hc
but this is not the question.
Upvotes: 0
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
Reputation: 9166
The following did the job for me:
du -hs */
Without the trailing slash the output was not restricted to directories.
Upvotes: 27
Reputation: 4712
create an alias:
alias subs="du -sch `find ./ -maxdepth 1 -type d`"
and I thing 'subs' is much shorter.
Upvotes: 0
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