A simple way to get a disk space usage summary

May 31, 2006

In the spirit of my little shell scripts, here's a simple way to get a useful summary of disk space usage on a Unix system:

du | sort -nr | less

(substitute the pager of your choice for less, and use 'du -x' as necessary.)

This is less pretty than the various graphical disk space visualization programs that float around, but I find it gives me pretty much the information I need. It's pretty easy to narrow down what areas of the filesystem, or what specific directories, are using up all of the space.

Applying it to various filesystems on stock machines is often interesting, especially /var; it's often a bit surprising just how much space some packages need. (For instance, a surprisingly large amount of disk space is going to /var/sadm/pkg on my Solaris test machine.)


Comments on this page:

From 128.100.49.60 at 2006-05-31 18:10:27:

Regarding /var/sadm/pkg getting large in Solaris, it is probably "undo.Z" and "obsolete.Z" archives needed to back out patches. It is usually safe to delete the "obsolete.Z" files, unless you have to backout multiple versions of the same patch. If it is a test machine, you can probably also get rid of the "undo.Z" files.

As for "du", we usually run something like "cd /homes; du -sk * | sort -rn > USAGE" nightly from cron so we know who's hogging the disks. :-)

Oscar@MIE

From 70.231.186.36 at 2006-05-31 20:38:35:

Yep, been using that for a while, or actually the aforementioned variant "du -sk *". In fact I use this under Windows with whatever random old dos unix utilities I have (hint: they don't do long filenames):

 usage.bat:
 du -sk * | c:\bin\sort -rn > %1

--nothings

By cks at 2006-05-31 22:19:42:

The advantage of plain 'du -k' over 'du -sk' for this is that it lets me see more than one level down at once. So I can see not just that /var/sadm is big, but that it's big because of /var/sadm/pkg, and that it's fairly well spread out in there.

(For Oscar's application this isn't necessary, since we're just using du of people's home directories to figure out how much disk space they're using. The details of what they're using it for are unnecessary (and might be a privacy intrusion to report).)

From 70.231.131.221 at 2006-06-01 19:22:49:

I have many deep directories, so the spew becomes too large without -s. Indeed, sorting without -s disrupts the structure for it to be very useful; for recursive examination I prefer to use a tool that does Treemapping (which I in fact learned about because I took a class from the aforementioned Ben Shneiderman in the aforementioned 1990s at the aforementioned UMCP).

Before I had a treemap for windows (I wrote one myself to start with), I used du -sk * | sort, and then manually recursively ran it again in the problematic directories, to avoid the aforementioned sorting confusion.

--nothings

By cks at 2006-06-01 21:48:40:

I have many deep directories, so the spew becomes too large without -s.

Hence the '| less' bit for me. I usually find that I only care about the first few screens, because by then it's generally pretty obvious where I need to trim stuff from.

(There are cases that are too complicated for this, for example when I have several separate hierarchies with about equal big usages and they get jumbled together. I usually deal with this with multiple windows and doing it separately in each hierarchy.)

Written on 31 May 2006.
« Fiddling with X selections from shell scripts
The cynical take on nofollow »

Page tools: View Source, View Normal, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed May 31 15:39:23 2006
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.