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.

I've got a web host (linux hosting) whose disk is almost completely full. How do I list out directories (and their subdirectories) by largest size to figure out where the biggest disk hogs are?

share|improve this question

migrated from webmasters.stackexchange.com Mar 8 '12 at 12:41

This question came from our site for pro webmasters.

add comment

2 Answers

up vote 6 down vote accepted

From a terminal:

Show disk free space (human readable)
df -h

Show sizes in the www-root

sudo du -sh /var/www/*

Apache log files

sudo du -sh /var/log/apache2/*

Etc.

These would be my first few guesses (databases as well). Also, your applications may have log files as well, so keep that in mind. ie:

sudo du -sh /var/www/railsapp/current/logs/*

Hope this helps!

share|improve this answer
    
Is there any way to use the "du" command to be a little bit more verbose? If I do "sudo du -sh /var/www*" I simply get back: 38G /var/www Would love to get more info about the offenders. For sure, it's not db's or log files. I've already checked those off as offenders. It's all web files. –  Keefer Mar 5 '12 at 16:57
    
you can just keep digging in... sudo du -sh /var/www/* will show sizes for anything in that folder –  InChargeOfIT Mar 5 '12 at 18:28
    
Use du -h --max-depth=2 /var/www. That gives you a recursion depth of 2 in the output, altogether /var/www, /var/www/*/ and /var/www/*/*/. You might want to extend it to sudo du -h --max-depth=2 /var/www | sort -nr | less. –  Eroen Mar 8 '12 at 12:54
add comment

A command line I've found very useful in finding out what's filling my disk is

du -ak | sort -rn | less

This will list all the files and directories under the current directory in decreasing order of total disk space usage. The numbers before each line are in kilobytes.

For example, running this command in /usr on my Ubuntu desktop produces output that starts like this:

7586900 .
3291420 ./share
2644256 ./lib
1093752 ./src
830268  ./share/doc
355520  ./bin
314976  ./lib/jvm
276240  ./share/fonts
272296  ./share/icons
247000  ./share/fonts/truetype
245196  ./share/doc/texlive-latex-extra-doc
242688  ./share/doc/texlive-latex-extra-doc/latex
230932  ./lib/openoffice
229560  ./lib/openoffice/basis3.2

From this output, I can notice for example that I have a lot of LaTeX documentation installed that I'm not really using. If I needed to free some disk space, that would seem like a good place to start.

Mind you, running this command can take a while if you have a lot of files. If you might want to keep the list around for a while, it may be a good idea to redirect it to a file instead of piping it directly to less.

share|improve this answer
add comment

Your Answer

 
discard

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.