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

Journeyman Geek
  • 127,463
  • 52
  • 260
  • 430
Alex Budovski
  • 432
  • 2
  • 5
  • 10
  • 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 00:50
  • 1
    But SU already has a very similar question! http://superuser.com/questions/9847/linux-utility-for-finding-the-largest-files-directories – Jonik Aug 04 '09 at 08:22
  • [No more disk space: How can I find what is taking up the space?](https://askubuntu.com/q/911865/253474) – phuclv Dec 18 '19 at 01:47

9 Answers9

17

ncdu

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

enter image description here

Pablo A
  • 1,470
  • 13
  • 21
Open SEO
  • 331
  • 3
  • 4
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)
Run5k
  • 15,723
  • 24
  • 49
  • 63
Jorge Israel Peña
  • 1,367
  • 4
  • 20
  • 26
  • This is actually really useful with a minor mod: `du -s * | sort -nr`. – Alex Budovski May 08 '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 00: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 '18 at 04: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](https://stackoverflow.com/questions/13282786/list-files-over-a-specific-size-in-current-directory-and-all-subdirectories). 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
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  
user31894
  • 2,789
  • 18
  • 9
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, ...).

Gaff
  • 18,569
  • 15
  • 57
  • 68
Ludwig Weinzierl
  • 8,015
  • 4
  • 29
  • 31
  • In ubuntu: k4dirstat and qdirstat. The last one more up to date. I don't like that they allow to delete folders – develCuy Jul 03 '19 at 04: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/

GLabs
  • 137
  • 1
  • 7
Ehtesh Choudhury
  • 1,478
  • 1
  • 15
  • 13
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)
sloth
  • 145
  • 7
  • 1
    I find the fact that you can pronounce that command highly entertaining. It sounds funny too. – jtbandes Jul 25 '09 at 00: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 04 '09 at 08: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 06:12
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.

balpha
  • 1,222
  • 3
  • 18
  • 27
  • 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. " http://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html – 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 07:31
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

Adam Matan
  • 8,090
  • 17
  • 59
  • 84
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

Pablo A
  • 1,470
  • 13
  • 21
hasen
  • 5,168
  • 11
  • 43
  • 51