19

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.)

migrated from stackoverflow.com 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
  • 5
    @mmyers: gave it to SU... SU needs Real Questions! – Shog9 Jul 25 '09 at 0:50
  • 1
    But SU already has a very similar question! superuser.com/questions/9847/… – Jonik Aug 4 '09 at 8:22
9

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

Also you can sort to have bigger folders first: du -shx * | sort -hr. For du:

  • -s, --summarize: display only a total for each argument
  • -h, --human-readable: print sizes in human readable format (e.g., 1K 234M 2G)
  • -x, --one-file-system: skip directories on different file systems

For sort:

  • -h, --human-numeric-sort: compare human readable numbers (e.g., 2K 1G)
  • This is actually really useful with a minor mod: du -s * | sort -nr. – Alex Budovski May 8 '10 at 12:36
  • 5
    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
  • du -shx * | sort -hr is good but it only returns the current directory. How would I do this system wide? And how could I exclude everything under 100mb? Thanks. – tymac Apr 17 '18 at 4:37
  • That's up to its invocation at the shell. So * is what makes it apply to everything in the current directory, but you could just as easily change that to e.g. some/other/path/*, or if you just want to run it on a single directory as a whole, then omit the * glob pattern. As for filtering things out, perhaps ask a separate question. – Jorge Israel Peña Apr 17 '18 at 19:58
  • To run it recursively system-wide, you may want to pair it up with find at some directory root and use its -exec parameter to invoke du. The find program itself can probably filter based on file size with something like size +100M. See this question. Maybe something like find / -size +100M -exec du -sh {} \; | sort -hr, though that's untested. – Jorge Israel Peña Apr 17 '18 at 20:04
10

ncdu

Is just great: CLI, ncurses based, fast, simple. Install it with sudo apt install ncdu.

enter image description here

5

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  
  • 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
3
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.

  • 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. " gnu.org/software/coreutils/manual/html_node/… – 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
3

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 kdirstat.sourceforge.net 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, ...).

3

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) : http://www.makeuseof.com/tag/how-to-analyze-your-disk-usage-pattern-in-linux/

3
du . -ha | sort -hr
  • -a, --all: write counts for all files, not just directories
  • -h, --human-readable: print sizes in human readable format (e.g., 1K 234M 2G)
  • 1
    I find the fact that you can pronounce that command highly entertaining. It sounds funny too. – jtbandes Jul 25 '09 at 0:51
  • 2
    -1, this is wrong. The "-h" in the the du command breaks the sorting. – therefromhere Jul 26 '09 at 10:22
  • 1
    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
2

Disk Usage Analyzer

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.

enter image description here

0

moonlight commander

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. Also you can Ctrl+space.

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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