Try our RSS feed

Unix Review > Archives > 2003 > November 2003
Print-Friendly Version
Shell Corner: Displaying Disk Space Usage with dispus November 2003
Hosted by Ed Schaefer

This month, Scott Rochford presents his Perl script, dispus. This personal productivity tool simpifies disk traversal and space usage analysis.

Displaying Disk Space Usage with dispus

With the plethora of monitoring tools available today, systems administrators are no strangers to scrambling for a keyboard to try and figure out where all that disk space has suddenly gone. In such situations, I found myself regularly typing an endless sequence of du -ks * | sort -n followed by cd yetanothersubdirectory as I narrowed down the source of the problem. Thus, I wrote the Perl script dispus, which does the typing for me. Not only that, it can also tell which directories are mount points for other filesystems and ignores them in its listings.

The script has been tested on Sun Solaris, SCO OpenServer, SCO UnixWare, Linux, Cygwin, and AIX. If you run the script successfully (or otherwise) on another system, I'd like to hear from you. The latest version can be found at

Type "?" at the "dispus>" prompt for a brief summary of the available commands. Here is a very brief sample of the display:

dispus v2.3 - Reading usage in /etc

   5,433,784 KB used of 5,719,136 KB available (96%)

   1.        149 KB   setup
              86 KB   moduli
   3.         21 KB   postinstall
              13 KB   termcap
               5 KB   man.config

 1 to 5 of 23 shown   ? - help   f - forward   q - quit

dispus> 1

dispus v2.3 - Reading usage in /etc/setup

   5,433,784 KB used of 5,719,136 KB available (96%)

               9 KB   perl.lst.gz
               8 KB   terminfo.lst.gz
               5 KB   installed.db.old
               4 KB   vim.lst.gz
               4 KB   tcltk.lst.gz

 1 to 5 of 74 shown   ? - help   f - forward   q - quit

dispus> ?

?       Display this help
0-9+    Traverse selected directory
.       Redisplay current directory
..      Traverse parent directory
c [dir] Change to specific directory
f       Page forward
b       Page back
q       Quit
s       Start $SHELL in current directory
k       Start /bin/ksh in current directory
![cmd]  Run command 'cmd' (or shell if omitted) in current directory

Explaining the commas Function

One particularly useful function is used to beautify the numbers for output by inserting commas for the thousandths:

# Put commas in number(s) to make them easy to read.

sub commas {
        return unless defined wantarray;  # void context, do nothing
        my @parms = @_;
        for (@parms) {
                if ($_ =~ s/(\d+)(\d\d\d)$/$1,$2/ == 1) {
                        until ( ($_ =~ s/(\d+)(\d\d\d),/$1,$2,/) != 1) { };
        return wantarray ? @parms : $parms[0];

This function returns either a scalar or array context, depending on which is passed to it (the skeleton for that was provided on the Perl man pages somewhere, if I recall). The function itself works by performing a sequence of search-and-replaces, first matching four digits at the end of the string and placing a comma before the last but-third digit, and then continuing to match at least four digits terminated by a comma and doing the same.

Explaining the Mount Points Detection

Perhaps another part of the script worth mentioning is the detection of mount points. This is done by constructing a list of mount points currently in use from the mount -v command, plus the list of mounts potentially mounted by the automounter from /etc/auto*master. This feature is a great boon, especially when browsing the root filesystem, where it can be very difficult to see what space in the du -s * output is on the current filesystem.

Scott Rochford is a Unix systems administrator. He speaks Korn shell, awk and Perl, and doesn't get out much. He has a wife and six computers to support. He can be reached at

Sys Admin Spotlight

New Products
March New Products

CMP DevNet Spotlight

Highlighting Multiple Search Keywords in ASP.NET
This article demonstrates how to highlight a multiple keywords within a DataGrid control, no matter where they are in the text.

In the News

Build An Affordable, High-Quality Podcast-Creation PC And Studio
Here's everything you need to know about creating an affordable podcast-ready PC and professional studio for creating high-quality podcasts.

Data Center Electricity Bills Double
A jump in the number of servers accounts for 90% of the additional power consumption, according to a study by Stanford's Jonathan Koomey. Power use per unit rises only slightly.

Lots Of Work Awaits Intel As It Pushes 80-Core Processors Out Of Experimental Stage
Challenges include figuring out who's going to need a supercomputer in their living rooms.

Oracle Tightens Ties Between TimesTen In-Memory System And 10g
New caching options in TimesTen Release 7 make it a fast front end for Oracle's flagship database

More Storage Options Are Close At Hand
Three external hard drives -- from Iomega, Western Digital, and Maxtor -- offer backup and storage.

Meet Alexander Lidow, CEO Of International Rectifier
Alexander Lidow is the CEO of International Rectifier, the world's oldest semiconductor company, which was founded in 1947 by Alexander's grandfather, Leon, and his father, Eric, who emigrated from Nazi Germany in 1937. It now has 5,800 employees and operates in 20 countries. He has a doctorate in applied physics from Stanford University and holds nine patents related to semiconductor technology.

It's A Big, Wide, Wireless World
The 3GSM World Congress is the biggest stage for the mobile computing industry. Here's what went on.


Subscribe to the UnixReview Newsletter

Subscribe to Sys Admin

Subscribe to THE journal for UNIX systems administrators. Receive 45% off your subscription by following the link below:


Sys Admin and The Perl Journal CD-ROM version 11.0

Version 11.0 delivers every issue of Sys Admin from 1992 through 2005 and every issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!

Order now!


Web-based Customizable Photo Editor
PXN8 is an online photo editor for install on your Web Server. Developed using web standards, PXN8 requires no plugins and can be easily customized and themed to suit your website identity. Sample themed editors are provided in JSP, PHP and ASP.

Rackspace Managed Linux Servers
Red Hat & MySQL certified backed by Rackspace Fanatical Support. Click to view our configurations.

UNIX and Linux Performance Tuning Simplified
SarCheck is a UNIX performance analysis and tuning tool for most UNIX and Linux systems. It produces recommendations and explanations, complete with supporting graphs and tables. Get the most from your hardware by keeping your systems tuned.

Bug Tracking Like You've Never Seen Before
Full API hooks ExtraView bug tracking into your applications, Web, source control & testing tools.

Wanna see your ad here?