Better disk usage information

Mar 09, '01 09:04:41AM

Contributed by: robg

The UNIX environment has two common commands for looking at disk usage - 'df' and 'du'. 'df' returns information about all mounted disks, and 'du' returns information about a given file or set of files. As installed in OS X, though, the 'df' and 'du' commands do not return easy to use information. For example, here's the 'df' output for one drive on my system:

Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/disk0s9 3121344 1314624 1806720 42% /osxfiles
Wouldn't it be much nicer if you could have it output like this:
Filesystem            Size  Used Avail Use% Mounted on
/dev/disk0s9 3.0G 1.3G 1.7G 42% /osxfiles
Read the rest of this article if you'd like to learn how to create a more usable "df" (and other!) commands.

NOTE: I have packaged four of the more useful of these utilities (ls, dircolors (sets the colors for the new ls), df, and du) into one downloadable archive. These are pre-compiled, and you'll just need to expand the archive with OpenUp or the command line (or the new StuffIt Expander). Move the files into /usr/localbin, and they should be ready to go. I have NOT included the 'man' pages, since I wasn't sure how to do that - read the GNU online help for info on each command, or compile the whole package.

I'd seen references to a "human readable" version of 'df' in various places, but the command ('df -h') failed on OS X - the '-h' option is not known. So last night I went out to the GNU website, and took a look at their page of available software. One of the packages listed is 'fileutils,' which includes a number of file utilities, including versions of 'df', 'du', and 'ls' with the color option. GNU has a page that describes each program in the package, along with a full set of instructions in just about any format you might want. So I downloaded version 4.0 of the package (GNU's web site has a list of other mirrors) and set out to install it. This was my first-ever attempt at a compile and install under OS X, so I wasn't sure what was going to happen.

NOTE: The following instructions assume you have the developer's tools for the PB, which are available on Apple's Developer website (you have to register for a free online membership). I make no claim that the following steps are safe for your system; I am a complete novice at UNIX compilation, so I may have done some things incorrectly (please, osxhints UNIX experts, correct me if you see mistakes!). Use at your own risk...that said, my machine still seems stable and usable :-).

The basic installation was fairly straightforward. Download the package and expand it, and you'll wind up with a directory named fileutils-4.0. Here's what you do next.

  1. Start a terminal session, and become root ('su' and your root password).
  2. cd /path/to/fileutils-4.0
  3. ./configure
    This runs a script which attempts to set the proper variables for a proper compile on your system. It takes a while (five minutes?) to run.

  4. Compile the package by typing
    make
  5. Install the programs and documentation by typing
    make install
    End your root session by typing 'exit'
That's really all there is to the installation. You'll see quite a few messages go by during each of these steps, but there's no required interaction. The compiler will install the pacakges into /usr/local/bin, and the man pages into /usr/local/man.

In the tcsh shell path (you can view it by typing 'setenv'), the /usr/local/bin directory appears in front of the system-wide /bin directory. So the newly installed commands should work from any directory. Try df -h in some directory, and see if you get the sample output shown above. You can also try the color ls command, with ls --color.

In order to get the "man" pages working for these new commands, you need to modify the MANPATH variable. You can set this once, and it will remain in effect for future termina sessions. MANPATH tells 'man' where to look for manual pages. Type the following into your terminal:
setenv MANPATH /usr/local/man:/usr/share/man:$MANPATH
This inserts our new local man pages ahead of the existing path, so when you type 'man ls', you'll get the man pages for the new command instead of the old. To use any of the old commands, you'll need to put their path in front of them, like this: /bin/ls, /bin/df, etc.

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20010309090441378