Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Which sequence of commands will tell me which files are the largest starting from a particular directory, including all sub directories? I want to know where all the space went.

Preferably just with regular unix'y commands.

If possible, try to keep it compatible with Sun OS 5.10 (perhaps in addition to regular Linux answers, not as a replacement, to keep it as general as possible.)

share|improve this question

migrated from Jul 25 '09 at 0:49

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

There are two votes for SU and two for SF. Which is more appropriate? This could belong on either one, in my opinion. – mmyers Jul 24 '09 at 18:09
@mmyers: gave it to SU... SU needs Real Questions! – Shog9 Jul 25 '09 at 0:50
But SU already has a very similar question!… – Jonik Aug 4 '09 at 8:22
up vote 9 down vote accepted

I personally like to use du -sh * to see how big each directory is within the current directory.

share|improve this answer
This is actually really useful with a minor mod: du -s * | sort -nr. – Alex Budovski May 8 '10 at 12:36
You can keep the file sizes in human readable format with du -sh * | sort -hr. – Jorge Israel Peña Apr 25 '14 at 0:18

basically you can use the du command. something like this

du -a /home | sort -rn |head -1

please look at the man page or info du for more options.

Or, you can use GNU find.

find /home/ -type f -printf "%s:%p\n" | sort -t":" -rn| head -1
share|improve this answer
Does 'find' on Sun OS 5.10 have an alternative I can use to -printf ? – Alex Budovski Aug 4 '09 at 8:05
Also, is there any way I can get the first command (du ...) to filter out directories? I only am really interested in files, like with your second command. – Alex Budovski Aug 4 '09 at 8:11

du . -ha | sort -nr

share|improve this answer
I find the fact that you can pronounce that command highly entertaining. It sounds funny too. – jtbandes Jul 25 '09 at 0:51
-1, this is wrong. The "-h" in the the du command breaks the sorting. – therefromhere Jul 26 '09 at 10:22
It's not wrong, just not portable. -h is a GNUism. Use -k instead with Sun OS. – Ludwig Weinzierl Aug 4 '09 at 8:20
+Ludwig I don't think you understood. By adding -h it makes the numbers human readable, therefor they are no longer numbers which can be used by the sort command. e.g. things would be sorted like this: "760K 784M 788K 860K 944K 985M" It should be du -ha | sort -hr or du -ha | gsort -hr (on osx after installing core utils) – Gerry Oct 18 '15 at 6:12
du -a | sort -n

would do the job. Using baobab (it's part of the gnome utils, so it's likely already installed on your system), you get a quite nice graphical breakdown of the used space.

share|improve this answer
Any reason to use -g instead of -n? "Use this option only if there is no alternative; it is much slower than --numeric-sort (-n) and it can lose information when converting to floating point. "… – therefromhere Jul 26 '09 at 10:25
@therefromhere: I used the manpage, which isn't quite as verbose as the site you linked. I just picked the first option that worked for the particular case. But you're right; I have edited my anwser. Thanks! – balpha Jul 27 '09 at 7:31

NCDU is just great : ncurses based, fast, simple,

aptitude install ncdu
share|improve this answer

Philesight run from the commandline, and results in a PNG plus web server, so you can view it online.

I found it through this list of disk usage programs. Useful list of programs, in addition to ncdu (which is small, zippy, and command-line only) :

share|improve this answer

Not command line but still unix'y: kdirstat

I use it to find out where all the space went and I like it much better than Disk Usage Analyzer (aka Baobab). It's one of the few KDE apps that is tolerated in my GNOME environment;-)

enter image description here

According to it runs on Solaris.

While KDirStat is a KDE program, it runs fine on every X11 desktop, i.e., it runs on Linux, BSD, and lots of other Unix-type systems (Solaris, HP-UX, AIX, ...).

share|improve this answer

If you want a list output with nice gui and navigation options, install the moonlight commander (mc in most package managers), and check "show directory sizes" in the command menu.

share|improve this answer

If you're using a debian/ubuntu based distro there are a couple of GUIs available in the repositories, which you can find using synaptic, such as Disk Usage Analyzer.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .