[Chapter 24] 24.9 How Much Disk Space?
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:41:36Z

#

| Chapter 24 Other Ways to Get Disk Space |

## 24.9 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 (1.33)) filesystems. Under BSD UNIX, the output from df looks like this:

>     % df
>     Filesystem   kbytes   used    avail  capacity  Mounted on
>     /dev/disk0a  889924  724308   76620    90%     /
>     /dev/disk3d  505463  376854   78062    83%     /benchmarks
>     /dev/disk5e  635287  553121   18637    97%     /field
>     /dev/disk2d  505463  444714   10202    98%     /research
>     /dev/disk1e  956094  623534  236950    72%     /homes
>     toy:/usr     498295  341419  107046    76%     /usr
>     toy:/          7495    5883     862    87%     /root
>        ...

This report shows information about five local filesystems and two remote filesystems (from the system toy). The /research and /field filesystems are nearly filled (98 and 97 percent, respectively), while the other filesystems still have a lot of room left. You might want to take some action to free up some storage on these two filesystems. Note that a BSD filesystem that is 100 percent full really has 10 percent free space&ndash;but only the superuser (1.24) can use this last 10& percent, and that usually isn't a good idea.

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 /homes or df& `.` (`.` means "the current directory" (1.21)).

- If your system uses NFS and you are interested only in local filesystems, use the command df -t& 4.2. 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.

- If you are interested in inode (1.22) 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, the report from df will look different. The information it presents, however, is substantially the same. Here is a typical report, taken from a XENIX system:

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

df | There are 1758 physical blocks (always measured as 512-byte blocks, regardless of the filesystem's logical block size) and 3165 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. The dfspace command (available on Systems V.3 and V.4) produces a significantly nicer report that's similar to the BSD-style df. For each filesystem, dfspace shows the amount of free storage both in kilobytes and as a percentage of the filesystem's size. You may also want to try the GNU df on the CD-ROM.

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. Here's a simple report from du:

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

This command shows that the current directory and all of its subdirectories occupy about 2.5 MB (2634 KB). The biggest directories in this group are stuff and howard, which have a total of 888 KB and 868 KB, respectively. The report also shows storage occupied by sub-subdirectories (/howard/work, etc.). du& does not show individual files as separate items, unless you invoke it with the -a& option. Note that System V reports disk usage in 512-byte blocks, not KB.

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.

- ML from O'Reilly & Associates' System Performance Tuning, Chapter 5

24.8 Save Space: tar and compress a Directory Tree |  | 24.10 zloop: Run a Command on Compressed Files