LINFO

The df Command



The df (i.e., disk free) command reports the amount of space used and available on currently mounted (i.e., logically attached to the system) filesystems.

A filesystem is a hierarchy of directories. Although everything mounted on a computer running Linux or another Unix-like operating system resides logically in the root directory (i.e., the top directory in the hierarchy of directories on a computer), on a typical installation some filesystems will be physically located on different partitions (i.e., a logically independent section of a hard disk drive) or on other storage devices such as a CDROM, floppy disk or a USB (universal serial bus) key drive, or even on another computer located elsewhere on a network.

df is commonly used to show not only the space available and used but also what filesystems are mounted, when capacity has been reached on a partition or other device, the number of inodes still available, and whether there is sufficient space on a partition to upgrade an existing program or to install a new program.

The basic syntax for df is:

df [option(s)] [device(s)]

The items in square brackets are optional. When used with no options and no arguments (i.e., input files), df generates a table that lists for each device its name, its size in one-kilobyte blocks, the number of kilobyte blocks used, the number of kilobyte blocks available, the percentage of blocks used and the mount point (i.e., the directory in which it is mounted).

When a device is provided as an argument, df will report data only for the filesystem physically residing on that device. If multiple devices are provided, the data will be reported for each listed device. Thus, for example, the following will provide information only for the partition (or other device) that contains the root directory:

df /

A device can be provided as an argument by using either its device name or its absolute pathname (i.e., its full path of directories relative to the root directory). Thus, for example, if the root directory (which is represented by a forward slash) resides on the third partition of the HDD (or on the third partition of the first HDD on a computer with multiple HDDs), whose device name is /dev/hda3, then the same result would be obtained by using the following:

df /dev/hda3

For many users, df's most useful option is -h, which tells it to express its output in human readable form. That is, it reports device sizes in megabytes and gigabytes as appropriate and appends the data with the letters M and G, respectively. The -m option tells df to report its data in one-megabyte (i.e., 1,048,576 bytes) blocks, and the -k option tells it to use one-kilobyte blocks (the default, but which is available as an option anyway).

The -i option instructs df to list inode usage instead of block usage. An inode is a data structure on a filesystem on a Unix-like operating system that stores all the information about a named file, directory or other filesystem object except its name and its actual data (i.e., all of its metadata except for its name). A data structure is an efficient way of storing data.

The -a (i.e., all) option tells df to include in its output filesystems that have a size of zero blocks, which are omitted by default. Such filesystems are typically special-purpose pseudo-filesystems, such as those for automatic device mounting use.

The -T option instructs df to add to its report the type of each filesystem listed (e.g., ext2, ext3, vfat or iso9660). The types reported are the same as those that can be included or excluded with the -t (i.e., type) and -x (i.e., exclude) options, respectively.

The --help option displays a brief help message and then exits. The --version option reports which version of df is currently installed. In contrast to many command line (i.e., all-text mode) programs, the -v option does not provide version information; it is merely ignored and does not produce an error message.

df's output data is not precise, and it can conflict with that provided by the du (i.e., disk usage) command, whose results likewise might not be exact. However, it is still a very useful command, and in many cases it is faster and more convenient than du.






Created March 20, 2006.
Copyright © 2006 The Linux Information Project. All Rights Reserved.