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?

link|improve this question
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? ;) – Kau-Boy Jul 11 '10 at 17:41
feedback

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

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

4 Answers

up vote 3 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 /.

link|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?) – Kau-Boy Jul 11 '10 at 17:35
You're welcome. See meta.stackoverflow.com/questions/50697/… – Thomas Jul 11 '10 at 17:36
Thanks. But evaluating a command on a console take only seconds ;) – Kau-Boy Jul 11 '10 at 17:42
1  
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
feedback

The following du invocation should work on BSD systems:

du -d 1 /
link|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 :( – Kau-Boy 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
feedback

I often has to find out biggest directories, so to get the 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.

link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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