Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Let's say I want to get the size of each folder of a linux file system. When I use ls -la I don't really get the summarized size of the folders.

If I use df I get the size of each mounted file system but that also doesn't help me. And with du I get the size of each subfolder and the summary of the whole file system.

But I want to have only the summarized size of each folder within the ROOT folder of the file system. Is there any command to achiev that?

share|improve this question

migrated from stackoverflow.com Jul 12 '10 at 18:25

This question came from our site for professional and enthusiast programmers.

This is probably more appropriate for superuser.com since it's not programming related. –  Lèse majesté Jul 11 '10 at 17:36
Oh I didn't know about that site. But thanks for pointing that out. I just signed up. Can somone migrate my question? Hey, but what if I wanted to execute that command in PHP? Is it than a programming related question? ;) –  2ndkauboy Jul 11 '10 at 17:41

6 Answers 6

up vote 159 down vote accepted
du -sh /*

-s to give only the total for each command line argument, -h for human-readable suffixes (optional). /* simply expands to all directories (and files) in /.

share|improve this answer
Hey that really worked out. Thanks for you answer and thanks for the very good explaination. (I will except your answer in 7 minutes. Why is there a time you have to wait to be able to accept an answer?) –  2ndkauboy Jul 11 '10 at 17:35
You're welcome. See meta.stackexchange.com/questions/50697/… –  Thomas Jul 11 '10 at 17:36
Thanks. But evaluating a command on a console take only seconds ;) –  2ndkauboy Jul 11 '10 at 17:42
If you have dot-directories in the root directory, you can use shopt -s dotglob to include them in the count. –  Philipp Jul 11 '10 at 21:55
It's very usefull, because it's simple and you can place what path you want instead of /*, e.g. ./ for current directory or ./* for each item in current directory. –  psur Aug 9 '12 at 6:22

The following du invocation should work on BSD systems:

du -d 1 /
share|improve this answer
My du (Ubuntu 10.4) doesn't have a -d option. What system are you on? –  Thomas Jul 11 '10 at 17:30
On my openSUSE it doesn't have a -d option either :( –  2ndkauboy Jul 11 '10 at 17:33
OK, then it's a BSD option only (I'm on OS X). –  Philipp Jul 11 '10 at 17:37
Right portable option combination on BSD/*NIX is du -sk /*. I hate the -k stuff soooo much. Linux' -h totally rocks. –  Dummy00001 Jul 11 '10 at 19:46

You might also want to check out xdiskusage. Will give you the same information, but shown graphically, plus allows to drill down (very useful). There are other similar utilities for KDE and even Windows.

share|improve this answer

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.

share|improve this answer
Here's a way to get it more readable du -sh /some/path | sort -hr | head -n 20 –  Xedecimal Jul 8 '13 at 15:49
@Xedecima the problem with using h is the sort doesn't know how to handle different sizes. For example 268K is sorted higher than 255M, and both are sorted higher than 2.7G –  chrisan Dec 27 '13 at 18:33
The -h (human readable) argument on the 'sort' command should properly read these values. Just like du's -h flag exports them. Depending on what you're running I'm guessing. –  Xedecimal Apr 14 '14 at 18:02

The existing answers are very helpful, maybe some beginner (like me) will find this helpful as well.

  1. 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" ; done
  2. Very 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 ./*
share|improve this answer

Be aware, that you can't compare directories with du on different systems/machines without getting sure, both share the same blocksize of the filesystem. This might count if you rsync some files from a linux machine to a nas and you want to compare the synced directory on your own. You might get different results with du because of different blocksizes....

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.