It always seems to happen late on
a Saturday night. You're getting paged because a
partition on one of the servers (probably the mail server) is
dangerously close to full.
Obviously, running a df will show
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/sda1 7040696 1813680 4863600 27% /
/dev/sda2 17496684 13197760 3410132 79% /home
/dev/sdb1 8388608 8360723 27885 100% /var/spool/mail
But you already knew that the mail spool was full (hence, the page
that took you away from an otherwise pleasant, non-mailserver related
evening). How can you quickly find out who's hogging
all of the space?
Here's a one-liner that's handy to
have in your .profile:
alias ducks='du -cks * |sort -rn |head -11'
Once this alias is in place, running ducks in
any directory will show you the total in use, followed by the top 10
disk hogs, in descending order. It recurses subdirectories, which is
very handy (but can take a long time to run on a heavily loaded
server, or in a directory with many subdirectories and files in it).
Let's get to the bottom of this:
rob@magic:~$ cd /var/spool/mail
Oops! It looks like my mail spool runneth over. Boy, I have orders of
magnitude more mail than any other user. I'd better
do something about that, such as appropriate new hardware and upgrade
the /var/spool/mail partition.
As this command
recurses subdirectories, it's also good for running
a periodic report on home directory usage:
[ several seconds later ]
For running simple spot checks while looking for disk hogs,
ducks can save many keystrokes (although if we
called it something like ds, it would save even
more, but wouldn't be nearly as funny.)