home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Unix Power ToolsUnix Power ToolsSearch this book

15.8. How Much Disk Space?

Two tools, df and du, report how much disk space is free and how much is used by any given directory. For each filesystem, df tells you the capacity, how much space is in use, and how much is free. By default, it lists both local and remote (i.e., NFS (Section 1.21)) filesystems. Under Linux or BSD Unix, the output from df looks like this:

% df
Filesystem  1K-blocks     Used    Avail Capacity  Mounted on
/dev/ad0s1a     99183    37480    53769    41%    /
/dev/ad2s1e   3943876  1873453  1754913    52%    /home
/dev/ad0s1f   3360437  1763460  1328143    57%    /usr
/dev/ad0s1e    508143    16925   450567     4%    /var
procfs              4        4        0   100%    /proc
toy:/usr     17383462 15470733   522053    97%    /toy

This report shows information about four local filesystems, the local procfs filesystem, and one remote filesystem (from the system toy). Note that a normal filesystem that is 100% full really has 5 to 10% free space -- but only the superuser (Section 1.18) can use this reserved space, and that usually isn't a good idea. The reserved space is primarily for recovering from the disk filling up for some reason; the superuser can still successfully copy files and the like to free up space. Special filesystems often don't do this sort of block reservation; procfs and ISO-9660 (CD-ROM and CD-R) filesystems don't care.

df can be invoked in several other ways:

  • If you already know that you're interested in a particular filesystem, you can use a command such as df /home or df . (. means "the current directory" (Section 1.16)).

  • If your system uses NFS and you are interested only in local (non-NFS) filesystems, use the command df -t ufs (most BSDs) or df -t ext2fs (most Linuxes). You should always use this command if remote file servers are down. If you have mounted remote disks that are unavailable, df will be extremely slow or hang completely.

  • If you are interested in inode usage rather than filesystem data capacity, use the command df -i. This produces a similar report showing inode statistics.

If you are using the older System V filesystem (for example, on Solaris), the report from df will look different. The information it presents, however, is substantially the same. Here is a typical report:

% df
/       (/dev/root ):    1758 blocks    3165 i-nodes
/u      (/dev/u    ):     108 blocks   13475 i-nodes
/usr    (/dev/usr  ):   15694 blocks    8810 i-nodes

[If you get this sort of output from df, you may be able to get the BSDish display by using df -P or df -k. You may also want to try the GNU df. -- DH]

There are 1,758 physical blocks (always measured as 512-byte blocks for this sort of df, regardless of the filesystem's logical block size) and 3,165 inodes available on the root filesystem. To find out the filesystem's total capacity, use df -t. The command df -l only reports on your system's local filesystems, omitting filesystems mounted by NFS or RFS.

It is often useful to know how much storage a specific directory requires. This can help you to determine if any users are occupying more than their share of storage. The du utility provides such a report. Generally you want to use the -k to du; by default its reports are in disk blocks and thus somewhat harder to read. -k asks df to report its numbers in kilobytes. Here's a simple report from du:

% du -k
107     ./reports
888     ./stuff
32      ./howard/private
33      ./howard/work
868     ./howard
258     ./project/code
769     ./project
2634    .

du shows that the current directory and all of its subdirectories occupy about 2.5 MB (2,634 KB). The biggest directories in this group are stuff and howard, which have a total of 888 KB and 868 KB, respectively. The total for each directory includes the totals for any subdirectories, as well as files in the directory itself. For instance, the two subdirectories private and work contribute 65 KB to howard; the rest of the 868 KB is from files in howard itself. (So, to get the grand total of 2,634, du adds 107, 888, 868, and 769, plus files in the top-level directory.) du does not show individual files as separate items unless you use its -a option.

The -s option tells du to report the total amount of storage occupied by a directory; it suppresses individual reports for all subdirectories. For example:

% du -s
2634    .

This is essentially the last line of the previous report. du -s is particularly useful for showing only the files in the current directory, rather than showing every directory down the tree:

% cd /home
% du -sk *
69264   boots
18236   chaos
1337820 deb

--ML, from System Performance Tuning (O'Reilly, 2002)

Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.