22

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

4

9 Answers 9

12

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)
5
  • This is actually really useful with a minor mod: du -s * | sort -nr. May 8, 2010 at 12:36
  • 5
    You can keep the file sizes in human readable format with du -sh * | sort -hr. Apr 25, 2014 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.
    – Edison
    Apr 17, 2018 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. Apr 17, 2018 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. Apr 17, 2018 at 20:04
17

ncdu

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

enter image description here

0
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  
2
  • Does 'find' on Sun OS 5.10 have an alternative I can use to -printf ? Aug 4, 2009 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. Aug 4, 2009 at 8:11
5

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

1
  • In ubuntu: k4dirstat and qdirstat. The last one more up to date. I don't like that they allow to delete folders
    – develCuy
    Jul 3, 2019 at 4:06
4

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

2
  • 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/… Jul 26, 2009 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, 2009 at 7:31
3

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

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)
4
  • 1
    I find the fact that you can pronounce that command highly entertaining. It sounds funny too.
    – jtbandes
    Jul 25, 2009 at 0:51
  • 2
    -1, this is wrong. The "-h" in the the du command breaks the sorting. Jul 26, 2009 at 10:22
  • 1
    It's not wrong, just not portable. -h is a GNUism. Use -k instead with Sun OS. Aug 4, 2009 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, 2015 at 6:12
3

Midnight Commander

If you want a list output with nice GUI and navigation options, install the Midnight Commander (mc in most package managers), and check "show directory sizes" in the command menu. Also you can Ctrl+space.

enter image description here

You must log in to answer this question.

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