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
  • 133,878

9 Answers9

18

ncdu

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

enter image description here

Pablo A
  • 1,733
Open SEO
  • 341
  • 3
  • 4
13

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
  • 16,463
  • 24
  • 53
  • 67
6

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

Gareth
  • 19,080
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
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
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,232
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,740
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,733
hasen
  • 5,269