65

Is there a way in Unix to see the biggest directories on disk?

I need to know why I'm almost out of space on the server,= and I don't know where most of the space is used.

Dave M
  • 4,494
aneuryzm
  • 1,804

10 Answers10

88

My favorite tool for this task is ncdu.

ncdu example screen

fracz
  • 324
halp
  • 2,528
77

Try: du --max-depth=7 /* | sort -n - it won't just tell you directories, and there will be duplicates, but it will list everything 7 levels deep and sort them by size order.

James L
  • 6,205
  • 1
  • 25
  • 26
8

I suggest you to use baobab, which will give you a graphical overview of your disk usage. It can also be used for remote folder (through ssh, ftp,...) to scan the disk usage on a remote server for instance.

Edit: If you would like to investigate the disk usage directly on the server with your shell access and not remotely, and you would like a tool more convenient than du, you can also have a try with durep which will generate a report of the disk usage with bar graphs.

uloBasEI
  • 696
5

Find biggest folders and their biggest subfolders successively

I parse through each folder level, to find the root of the problem, like this:

iteration 1

du -h --max-depth=1 -t 1G /Dir0/Dir1 | sort -rh | head -10

iteration 2

du -h --max-depth=1 -t 1G /Dir0/Dir1/biggestFolderInDir1 | sort -rh | head -10

-h: human readable sizes

-t 1G: only list directories bigger than 1G

sort -h: compare human readable numbers (e.g., 2K 1G)

sort -r: reverse the output to list biggest folders first

head -10: only list the first (biggest) 10 items

(optionally) ignore 'cannot read directory' messages

du -h --max-depth=1 -t 1G /Dir0/Dir1 2>/dev/null | sort -rh | head -10

Manpages: du - sort - tail

Amanda
  • 153
3

I usually use something like this:

du -ch / | sort

You can apply a depth restriction using --max-depth= if you don't want to see past a certain level from your target, like so:

du -ch --max-depth=4 /
0

Try df & du -sh /. And recursively du -sh. Not the best solution though.

0

Something like

sudo du / | sort -n

Will give you a quick answer (last entries are largest files/directories)

N J
  • 101
0

# cd /; du -shb | sort -nr > /root/home/disk-space-report.txt

LawrenceC
  • 1,262
0

I always use syntax like

du -sm --max-depth=4 /path/i/want/to/drill | sort -nr | head -n 20.

max-depth and head parameters can vary, of course, but the above would list 20 biggest directories.

0

I'm regularly running du -dak > du-dak.out at the top of each file system. Then, I can get a graphical display with xdu < du-dak.out. This can be done remotely after transferring the du-dak.out file over the network should you only have text access.

http://sd.wareonearth.com/~phil/xdu/

jlliagre
  • 9,031