1. Overview

Efficient disk space management ensures optimal performance and minimizes unexpected downtime. Several helpful command-line applications are available in Linux environments to help us monitor disk space utilization.

In Linux, the df (Disk free) utility shows details about the disk space that the file systems are using.

In this tutorial, we’ll see how to use the df utility with practical examples.

2. Syntax of the df Command

df command alone in the terminal displays the mounted file systems’ disk space usage. Here’s what its syntax looks like:

$ df
Filesystem     1K-blocks     Used Available Use% Mounted on
tmpfs             822628     1612    821016   1% /run
/dev/sda2       44824484 18265996  24249112  43% /
tmpfs            4113136        0   4113136   0% /dev/shm
tmpfs               5120        8      5112   1% /run/lock
tmpfs             822624       80    822544   1% /run/user/125
tmpfs             822624      120    822504   1% /run/user/1001

Now, let’s explore the above syntax:

  • The Filesystem/em> displays the name of each file system.
  • The 1K-blocks column shows the total size of a file system in bytes.
  • The Used/em> column displays the total space currently used by the file system.
  • The Available column indicates the size of available disk space.
  • The Use% column shows the total space a file system uses in percentage.
  • Mounted on represents the directory on which the file system is mounted.

For instance, tmpfs is the temporary file system that contains 822628 bytes of space.  With 1612 bytes being used and 821016 bytes being available, the system only utilizes 1% of the space on the /run path where the tmpfs is mounted.

3. General Usage

The df command offers various options to enhance its functionality. Thus, let’s begin by illustrating some of these options.

3.1. The -h Option

First, the most commonly used option -h within the df command modifies the output as more human-readable. Moreover, it formats the sizes in a way that is easier for humans to understand by displaying them in units like K for kilobytes, M for megabytes, and G for gigabytes:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           804M  1.6M  802M   1% /run
/dev/sda2        43G   18G   24G  44% /
tmpfs           4.0G     0  4.0G   0% /dev/shm
tmpfs           5.0M  8.0K  5.0M   1% /run/lock
tmpfs           804M   80K  804M   1% /run/user/125
tmpfs           804M  120K  804M   1% /run/user/1001

In return, this command’s output displays the disk space used and available for each file system in K, M, and G units.

3.2. Specifying Filesystem Name With -h Option

Meanwhile, if we want to get disk space information regarding a specific file system, we can use a label of a file system after the -h option:

$ df -h /dev/sda2
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        43G   18G   24G  44% /

Finally, the output returns display the space usage information for /dev/sda2 only.

3.3. The -a Option

Sometimes, the system may have file systems with 0 memory blocks used. Thus, in the df command, typically, users apply the -a option to display all mounted file systems, including those with 0 space used:

$ df -a
df: /run/user/1001/doc: Operation not permitted
Filesystem     1K-blocks     Used Available Use% Mounted on
sysfs                  0        0         0    - /sys
proc                   0        0         0    - /proc
udev             4081272        0   4081272   0% /dev
devpts                 0        0         0    - /dev/pts
tmpfs             822628     1624    821004   1% /run
/dev/sda2       44824484 18303020  24212088  44% /
.....

Here’s the breakdown of the above output:

  • the sysfs, proc, and devpts file system have size 0. Hence, no memory blocks are used.
  • the udev file system has 4081272 bytes of space, while 0 bytes are used.
  • the details regarding the other mounted file systems in use are also displayed.

3.4. The –-total Option

Sometimes, we may need a summarized line after the output and an overview of the disk space used. For this purpose, the option –total tells the df command to display a summary line at the end of the output:

$ df --total
Filesystem     1K-blocks     Used Available Use% Mounted on
tmpfs             822628     1624    821004   1% /run
/dev/sda2       44824484 18303268  24211840  44% /
tmpfs            4113136        0   4113136   0% /dev/shm
tmpfs               5120        8      5112   1% /run/lock
tmpfs             822624       80    822544   1% /run/user/125
tmpfs             822624      124    822500   1% /run/user/1001
total           51410616 18305104  30796136  38% -

Finally, an extra row labeled total displays disk space usage throughout all file systems. Usually, this line contains the total capacity of all file systems, the overall sum of space consumed, space available, and the percentage of disk utilization.

3.5. The -T Option

We often want to see the type of each file system and the space used. Thus, the -T option in the df command outputs the type of each file system. Also, it can be helpful for system administrators while working on different types of file systems:

$ df -T
Filesystem     Type  1K-blocks     Used Available Use% Mounted on
tmpfs          tmpfs    822628     1624    821004   1% /run
/dev/sda2      ext4   44824484 18303324  24211784  44% /
tmpfs          tmpfs   4113136        0   4113136   0% /dev/shm
tmpfs          tmpfs      5120        8      5112   1% /run/lock
tmpfs          tmpfs    822624       80    822544   1% /run/user/125
tmpfs          tmpfs    822624      124    822500   1% /run/user/1001

Here, the system displays the type of each file system and other information.
For example, the /dev/sda2 file system has a type ext4, short for Fourth Extended Filesystem.

3.6. The -x Option

Sometimes, we want to exclude the information regarding certain types of file systems from the output. So, we must use the -x flag and specify the type in the df command.
Here, we’re using the -x option with the type tmpfs:

$ df -x tmpfs
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda2       44824484 18303480  24211628  44% /

Consequently, excluding all the tmpfs type file systems, a single output line is displayed. However, the system displays details regarding space usage for the ext4 file system.

3.7. The -i Option

Inodes or index nodes are data structures that save information regarding files and directories. This information includes file types, permissions, file size, timestamps, and pointers.

Here, we’re using the -i option within the df command to check the inode usage on the system:

$ df -i
Filesystem      Inodes  IUsed   IFree IUse% Mounted on
tmpfs          1028284   1132 1027152    1% /run
/dev/sda2      2867200 363656 2503544   13% /
tmpfs          1028284      1 1028283    1% /dev/shm
tmpfs          1028284      6 1028278    1% /run/lock
tmpfs           205656     87  205569    1% /run/user/125
tmpfs           205656    177  205479    1% /run/user/1001

Finally, this command’s output depicts the number of inodes on the mounted file systems, followed by the used and free inodes. The IUse% column represents the space used against each inode.

Additionally, the h option combined with the -i option can display the human-readable output for space usage of inodes:

$ df -ih /
Filesystem     Inodes IUsed IFree IUse% Mounted on
/dev/sda2        2.8M  356K  2.4M   13% /

Finally, the output shows that the file system has mounted 2.8M inodes in total on /dev/sda2, with 356K being used and 2.4M available. The usage is 13%.

4. Conclusion

In this article, we’ve discussed the df command in detail. Naturally, the df command displays in-depth information about the disk space usage for different file systems.

First, we checked how to display disk space information in a machine-readable format according to the type of file systems and information regarding file systems with 0 space block usage. Afterward, we learned to display the sum of total space utilized by all file systems. Finally, we used the df command to exclude information about certain file systems and displayed inode availability.