Josh Tarchuk

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 what's left:

rob@magic:~$ df
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
rob@magic:/var/spool/mail$ ducks
8388608 total
1537216 rob
55120 phil
48800 raw
43175 hagbard
36804 mal
30439 eris
30212 ferris
26042 nick
22464 rachael
22412 valis

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:

root@magic:/home# ducks
[ several seconds later ]
13197880 total
2266480 ferris
1877064 valis
1692660 hagbard
1338992 raw
1137024 nick
1001576 rob
925620 phil
870552 shared
607740 mal
564628 eris

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


 

Showing messages 1 through 11 of 11.

  • How about xdu?
    2004-01-23 16:04:04 riddet [Reply | View]

    How come nobody has mentioned xdu?

    Very useful for detecting disk hogs graphically.

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

  • thkx
    2003-06-20 23:45:36 anonymous [Reply | View]

    comes in handy...
    add -h to display results in Megs, Gigs, KBs, etc..
    /r0d
  • No -h ?
    2003-05-07 20:42:08 anonymous [Reply | View]

    alter it to du -cksh to show in Human readable output (2G, 55K etc) and save yourself some mental arithmatic :-)
    • No -h ? = a broken sort -nr
      2003-05-09 13:34:08 anonymous [Reply | View]

      Would have to rethink the sort mechinism for 'h' usage in the script. Rather do the math :-)
  • another (better?) way to do this
    2003-03-19 15:29:31 anonymous [Reply | View]

    du -x --max-depth=1 |sort -n


    This will limit it to the current filesystem.
    I think it will only work on GNU du

    • another (better?) way to do this
      2003-07-26 16:23:13 anonymous [Reply | View]

      Or:
      ls -a | grep -v -e '^\.\+$' | xargs -i du -cks {} |sort -rn |head -11

      or even:
      ls -a | grep -v -e '^\.\.$' | xargs -i du -cks {} |sort -rn |head -11
      which has the nice side effect of showing the total size of the directory (obviously the contents of the directory are bigger than the largest file in the directory).

      • another (better?) way to do this
        2003-07-26 16:23:31 anonymous [Reply | View]

        Opps - take off the -c in du in the above.
        ls -a | grep -v -e '^\.\.$' | xargs -i du -ks {} |sort -rn |head -11
        • another (better?) way to do this
          2003-12-23 03:45:20 anonymous [Reply | View]

          Maybe you will like this one.
          ls -A don't show the current and parent directory (.&..) so "du" don't go up.

          ls -A | grep -v -e '^\.\.$' |xargs -i du -ks {} |sort -rn |head -11 | awk '{print $2}' | xargs -i du -hs {}

        • another (better?) way to do this
          2003-12-23 03:43:34 anonymous [Reply | View]

          Maybe you will like this one.
          ls -A don't show the current and parent directory (; &..) su du don't go up.

          ls -A | grep -v -e '^\.\.$' |xargs -i du -ks {} |sort -rn |head -11 | awk '{print $2}' | xargs -i du -hs {}

    • another (better?) way to do this
      2003-05-12 11:05:22 anonymous [Reply | View]

      I would agree that this is better, as this version will catch dotfiles and dotdirectories, while the book one will not.

      I had completely missed that my .wine directory was taking up the lions share of my home directory with my usual "du -s * | sort -rn | head" command.

    • another (better?) way to do this
      2003-03-28 14:48:48 anonymous [Reply | View]

      And then call it what? 'dux'? ;-)

 

 



Blackcomb.ca My little corner of the web

Google:
submit

Home
Josh
Work
Linux

"The secret to creativity is knowing how to hide your sources."
A. Einstein

NEWS:
New site


No endorsement or approval of any third parties or their advice, opinions, information, products or services is expressed or implied by any information on this Site or by any hyperlinks to or from any third party websites or pages. ©2004 Josh Tarchuk  |  Blackcomb.ca