Check Disk Space with the Commands df and du

Use 'df' and 'du' to check filesystem use at a global or directory level

Businessperson typing on computer

 Blend Images / Klaus Tiedge / Brand X Pictures / Getty Images

Use the df utility to review a summary of the available and used disk space on your Linux system. With the -h option, it shows the disk space in human-readable form. The du utility, by contrast, lists space utilization on a directory-and-subdirectory basis.

A Linux system consists of one or more filesystems. Unlike Windows computers, a Linux filesystem doesn't need to be a specific drive partition. Instead, a Linux filesystem includes partitions, clusters of partitions, devices, or sandboxed folders (for example, for Snap packages) that the system treats separately.

Output of the df Command

The output of the df command structures the results into six columns:

  • Filesystem: The name of the filesystem. Filesystems that aren't temporary (tmpfs) and aren't physically separate sometimes list as being a loopback device, iterated at /dev/loopnn.
  • 1K-blocks: The number of kilobyte blocks available to the filesystem.
  • Used: The number of blocks used.
  • Available: The number of blocks available. If the filesystem dynamically updates, this value will always be zero. Snap packages, for example, grow and shrink as necessary, so df always lists them as fully used.
  • Use%: The ration of available-to-used blocks.
  • Mounted on: The location where the filesystem is mounted in the system.
Linux df command output

Output of the du Command

The du command, on the other hand, shows the disk space used by the files and directories in the current directory. The -h option makes the output easier to understand.

The Linux du command

By default, the du command lists all subdirectories to show how much disk space each has occupied. Consolidate the output with the -s option, which only shows a summary. Unless you run sudo du, however, you'll see permission-denied errors for any directories to which the logged-in account lacks read access.

To show the disk usage of a directory other than the current directory, insert that directory name as the last argument.

Both du and df admit to several useful but relatively rare command switches. Read the manpages for each command to explore approaches to fine-tune the inputs and the outputs of these commands.