Getting Disk and Directory Information: du, df
The du and df commands are great examples of where a command-line tool really shines. Finding out how much space your files are using, or how much space is left on your various assorted volumes and drives is not a pleasant process under the Finder. Certainly, the display of drive space on a volume that appears in the bottom of every Finder window is a convenient way to keep track of disk usage, but if you want to find out what drive has the most free space, there isn't a good way to see this information without either clicking through every drive and looking at the window, or running an auxiliary disk-monitoring tool like Disk Utility. At the command line, it's two keystrokes:
brezup:~ ray$ df Filesystem 512-blocks Used Avail Capacity Mounted on /dev/disk0s3 20447232 16643456 3599304 82% / devfs 186 186 0 100% /dev fdesc 2 2 0 100% /dev <volfs> 1024 1024 0 100% /.vol /dev/disk0s5 41418752 28786624 12632128 70% /Volumes/Software /dev/disk0s7 54263808 52485896 1777912 97% /Volumes/Wills_Data /dev/disk0s9 10223616 8979656 1243960 88% /Volumes/DVD1 /dev/disk0s11 10223616 6687424 3536192 65% /Volumes/DVD2 /dev/disk0s13 10223616 8662360 1561256 85% /Volumes/DVD3 /dev/disk0s15 7665760 1582288 6083472 21% /Volumes/CD automount -nsl  0 0 0 100% /Network automount -fstab  0 0 0 100% /automount/Servers automount -static  0 0 0 100% /automount/static
If you prefer the output in kilobytes, instead of 512-byte blocks (yes, that seems a silly default to us as well), you need to add the -k option.
Likewise, the du command tells you about the disk space being used by various files or directories. If one of your volumes has unexpectedly filled up, and you don't know with what filled it or where the offending files landed, wading through the filesystem with the Finder looking for the large file or files can be tedious. Again, at the command line, getting at the information (sometimes too much of it!) is only a few keystrokes away. The du command will tell you the size of every file on your system with four keystrokes, if you choose:
brezup:~ ray$ du / du: /.Metadata: Permission denied du: /.Trashes: Permission denied 0 /.vol/234881026 0 /.vol 984 /Applications/Address Book.app/Contents/MacOS 8 /Applications/Address Book.app/Contents/Resources/ABLargeTypeWindow.nib 8 /Applications/Address Book.app/Contents/Resources/da.lproj/ABCarbonLayoutName.nib 8 /Applications/Address Book.app/Contents/Resources/da.lproj/ABConverterProgress.nib 24 /Applications/Address Book.app/Contents/Resources/da.lproj/ABDistribution.nib 16 /Applications/Address Book.app/Contents/Resources/da.lproj/ABDotMacSharingProgress.nib ...
This listing goes on and on, and gives the size of every file I currently have permission to read on the entire system.
If I want to limit the output to only a summary for each file or directory, rather than a line of output for every individual item in the hierarchy, I can use the -s option, shown here looking only at the files and directories in my home directory:
brezup:~ ray$ du -s ~/* 8 ./Adobe SVG 3.0 Installer Log 0 ./Applications 786792 ./Desktop 6078256 ./Documents 896848 ./Library 1236624 ./Mail 0 ./Movies 53632 ./Music 0 ./Network Trash Folder 6269584 ./Pictures 32 ./Public 32 ./Shared 584 ./Sites 0 ./TheFindByContentFolder 16 ./TheVolumeSettingsFolder 32 ./ZaurusBackup 13936 ./joray 0 ./mnt 136 ./output 8 ./tmp
If I had issued the command as du -s ~/, I would have gotten only a summary response for my home directory as a directory, rather than every file and directory in it. Again, the -k option is a good thing to use if you prefer your response in kilobytes, rather than in 512K disk-block units. Table 10.24 shows the syntax and options for df, and Table 10.25 shows the syntax and options for du.
Table 10.24. The Command Documentation Table for df
Displays free disk space.
df [-ailn] [-b | -h | -H | -k | -m | -P] [-t <type>] [-T type] [<file> | <filesytem> ...]
Shows information for all filesystems, even if they were mounted with MNT_IGNORE, a flag that tells the system to ignore them in normal statistics reporting.
Includes statistics on the number of free inodes.
Displays statistics only about mounted filesystems with the MNT_LOCAL flag set. If a nonlocal filesystem is given as the argument, a warning is issued and no information is displayed.
Prints out previously obtained statistics from the filesystem. This option should be used if it is possible that one or more filesystems are in a state such that there is a long delay before they can provide statistics. For example, if you're using df as a component of an automated system monitoring your machine, it wouldn't be good for it to hang permanently waiting for data if one of your drives died, or if a volume mounted from a remote server was disconnected. The option allows the df to report previously valid statistics, instead of perhaps waiting forever, for a failed resource to report current data.
Report the statistics in 512-byte blocks.
Reports the statistics in human-readable form, appending appropriate suffixes to the numbers to keep the printed lengths down to convenient sizes; reports the numbers themselves in the base-2 version of kilobyte (1024 bytes), and so on.
Reports the statistics in human-readable form, appending appropriate suffixes to the numbers to keep the printed lengths down to convenient sizes; reports the numbers themselves in the base 10 version of kilobytes (1000 bytes), and so on.
Reports the statistics in 512-byte blocks.
Reports the statistics in megabyte (1048576-byte) blocks.
Displays information for filesystems of the specified type. More than one type may be specified in a comma-separated list of the list of filesystem types. Using this option you can limit your responses to only hfs for normal Mac filesystems, nfs for typical Unix network filesystems, ufs for typical Unix local filesystems, cd9660 for ISO9660 CD ROMs, as well as other filesystem types listed by the lsvfs command.
If the environment variable BLOCKSIZE is set, and none of the size override options are used, the block counts are displayed according to the environment variable.
Table 10.25. The Command Documentation Table for du
Displays disk usage statistics.
du [-H | -L | -P] [-I mask] [-a | -s | -d depth] [-c] [-h|k] [-x] [<file> ...]
du displays the file system block usage for each file argument and for each directory in the file hierarchy rooted in each directory argument. If no file is specified, the block usage of the hierarchy rooted in the current directory is displayed.
Follows symbolic links on the command line. Symbolic links encountered during tree traversal are not followed.
Follows all symbolic links.
Does not follow symbolic links.
Ignores files matching <mask>.
Displays an entry for each file in the file hierarchy.
Displays only the grand total for the specified files.
Prunes the output to only <depth> directories deep.
Displays the grand total after all the arguments have been processed.
Human-readable output as with df's -h option.
Displays the statistics in 1024-byte blocks. Default is 512-byte blocks.
Does not traverse file system mount points.
du counts the storage used by symbolic links and not the files they reference unless -H or -L is specified. If either -H or -L is specified, the storage used by a symbolic link is not counted and statistics including the target of the link are displayed instead. -H, -L, and -P override each other. The option specified last is the one executed.
Files with multiple hard links are counted and displayed once per du execution.
If the environment variable BLOCKSIZE is set and the -k option is not used, the block counts are displayed according to the environment variable.