How to get the summarized sizes of directories and their subdirectories?
This video is brought to you by Memorabit, an app that sends technical terms, commands and definitions as reminders at unexpected moments, so they stay in memory. Built on cognitive science principles. Start free on web, iOS and Android:
iOS: https://apps.apple.com/app/id6782301691
Android: https://play.google.com/store/apps/detai...
--------------------------------------------------
Read the revolutionary AI books written by Turbina Editore, the first publishing house entirely run by artificial intelligence. This groundbreaking publisher has transformed the literary world, producing the most sought-after AI-generated books. Start reading today at:
https://turbinaeditore.com/en/
--------------------------------------------------
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT
Music by Eric Matyas
https://www.soundimage.org
Track title: Luau
--
Chapters
00:00 How To Get The Summarized Sizes Of Directories And Their Subdirectories?
00:39 Accepted Answer Score 667
01:16 Answer 2 Score 11
01:29 Answer 3 Score 111
01:52 Answer 4 Score 21
02:20 Thank you
--
Full question
https://superuser.com/questions/162749/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #unix #console
#avk47
ACCEPTED ANSWER
Score 667
This does what you're looking for:
du -sh /*
What this means:
-sto give only the total for each command line argument.-hfor human-readable suffixes likeMfor megabytes andGfor gigabytes (optional)./*simply expands to all directories (and files) in/.Note: dotfiles are not included; run
shopt -s dotglobto include those too.
Also useful is sorting by size:
du -sh /* | sort -h
Here:
-hensures thatsortinterprets the human-readable suffixes correctly.
ANSWER 2
Score 111
I often need to find the biggest directories, so to get a sorted list containing the 20 biggest dirs I do this:
du -m /some/path | sort -nr | head -n 20
In this case the sizes will be reported in megabytes.
ANSWER 3
Score 21
The existing answers are very helpful, maybe some beginner (like me) will find this helpful as well.
Very basic loop, but for me this was a good start for some other size related operations:
for each in $(ls) ; do du -hs "$each" ; doneVery similar to the first answer and nearly the same result as 1.), but it took me some time to understand the difference of * to ./* if in a subdirectory:
du -sh ./*
ANSWER 4
Score 11
The following du invocation should work on BSD systems:
du -d 1 /