Linux Commands

Linux df Command with Examples

In Linux, the “df” command stands for “disk free” that checks the available space across the different file systems. Whenever you run this Linux command-line utility, it displays the amount of used and available blocks, total disk space, and a summary of where the file system is mounted.

This article explains the “df” command with useful examples. The supported content of this guide is as follows:

Let’s start the guide with the “df” command.

How Does the “DF” Command Work?

The “df” command extracts the disk space information that has filename arguments The general syntax of the “df” command with different options is provided in the following:

General Syntax:

$ df [option]

The “option” over here refers to the flags which are used in conjunction with the “df” command.

Option Description
-a It is used to include all duplicate and dummy files, whether they are having zero block sizes.
-b When we use the “-b” option in the terminal, it scales the sizes by file sizes.
-h This option displays the size of powers.
-l It lists down the disk space information of the local file system only.
-p When typing this “df” option in the terminal, it utilizes only the POSIX output format.
-t  This option prints the total for size, availability, and used space.
-v This is used to print the version information of the “df” command tool.

To explore other variants of the “df” command, the user can utilize the “help” utility:

$ df -- help

Example 1: Display the Space of the Currently Mounted File Systems in Linux

Whenever we use the “df” command without any flags or options, it displays the free space of all the currently mounted file systems in Linux in the following manner:

$ df

It prints the complete statistics of disk space in tabular form including total, used, available, and the root directory where the files are mounted.

Example 2: Display the Space of All the File Systems in Linux

However, suppose you want to look at the free space of all the file systems regardless of whether they are mounted or unmounted, accessible or inaccessible. In that case, you can use the following variation of the “df” command:

$ df -a

The output displays all duplicate and dummy files, whether they are having zero block sizes.

Example 3: Display the Total Space of File Systems in Linux

If you want to get a total figure of the space of the file systems in Linux, you can execute the following command:

$ df --total

It displays the total space of all the file systems in the last row of the output.

Example 4: Display the Disk Space in Human-Readable Format in Linux

The disk space can also be displayed in a human-readable format in Linux in the following manner:

$ df -h

The disk space of the file systems can be displayed in a human-readable format.

Example 5: Display the Disk Space in Specified Units in Linux

If you want the disk space to be displayed in the specified units in Linux, you can use the following variant of the “df” command:

$ df -<unit>

You can replace the “unit” with “k”, “m”, and “h” for “kilobyte”, “megabyte”, and “gigabyte”, respectively.

Since we use the “k” flag, the disk space of our file systems in kilobytes as shown in the following:

$ df -k

Example 6: Display the Disk Space of a Specified File System in Linux

You can also just display the information about a specific file system in Linux. This can be done with the following command:

$ df -t <Filesystem>

You can replace the “Filesystem” with the name of the file system whose information you want to view:

$ df -t tmpfs

The information which is related to our specified file system is shown in the image.

Example 7: Display the Disk Space of All Files Systems Except for the Specified File System

You can even choose to display the information regarding all the file systems while excluding a single file system with the following command:

$ df -x <Filesystem>

Again, you can replace the “Filesystem” with the file system’s name whose information you want to exclude:

$ df -x tmpfs

The information which is related to all of our file systems, excluding the specified file system, is shown in the image.

Conclusion

The “df” is a standard tool to display the disk space information in Linux-like systems. Using this command, the users can display the space of the currently mounted file systems, total space, human-readable format, disk space in specified units, and disk space of a specified file system. This article provides the “df” command with syntax and multiple examples.

About the author

Syed Minhal Abbas

I hold a master's degree in computer science and work as an academic researcher. I am eager to read about new technologies and share them with the rest of the world.