The “df” Command in Linux [11 Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The df command in Linux displays available and used space in file systems. As you know, no machine has unlimited disk space and checking available space is necessary sometimes. The df command in Linux is mainly run by the system administrator but doesn’t require special permission. So, anyone can use the df command. In this article, you will learn everything you need of the df command with tons of examples.

A. Description

The “df” comes from “disk free” and does what it sounds like. Moreover, it can take arguments and comes with multiple options. So, you can customize your output according to your preference.

B. Syntax

The syntax of the df command in Linux is simple. The syntax is df, followed by one or multiple options and one and multiple files or directories.

df [OPTION]... [FILE]...

Note: In the above syntax OPTION and FILE  enclosed by square brackets and followed by 3 dots represents that multiple options and argument can be utilized at the same time.

C. Options

There are many options available for the df command in Linux. You can check those yourself by going to the manual page. Type the following command-

man df

Useful Options

  • -a, –all (displays all file systems including pseudo, duplicate, inaccessible)
  • -h, –human-readable (shows sizes in powers of 1024)
  • -H, –si (shows sizes in powers of 1000)
  • –output (prints output in a customised See the manual page for details)
  • –total (ignores insignificant entries to available space and shows a grand total)
  • -t, –type (only prints a specific type of file system. See the manual page for details)
  • -x, –exclude-type (prints file system excluding specific file system type. See the manual page for details)
  • -T, –print-type (prints file system type)
  • -i, –inodes (lists inodes information)
Note: The options in Linux CLI (Command Line Interface) are all case-sensitive, So be cautious while using them.

Practical Examples of the “df” Command in Linux

Now, let’s see some practical examples of the df command in Linux.

Example 1: Display the Disk Space Usage Using the “df” Command in Linux

It is the most common use of the df command. To view your disk space usage, follow the steps below:

  1. At first open the Ubuntu Terminal.

  2. Type the following command in the command prompt:

    df
  3. Now, press the ENTER button.

You will see multiple columns with a title at the first line like below.Showing disk space information using the df command in linux

OUTPUT ANALYSIS
  • Filesystem (A logical collection of files or directories on a disk drive or partition)
  • 1K-blocks ( Using 1KB as a unit)
  • Used (Used space)
  • Available (Available Space)
  • Use% (Used space in percentage)
  • Mounted on (The location of the Linux directory tree where a storage device is associated)

Similar Readings


Example 2: Displaying the Disk Space Usage in Human-Readable Form

To make the output more understandable for a human you can follow the steps below.

  1. At first open the Ubuntu Terminal.
  2. Type the following command in the command prompt:
    df -h
  3. Now, press the ENTER button.

As you can see, our output is more readable now.Showing disk space information in Human Readable form

Example 3: Displaying Used and Available Space for a Directory

You can also give a directory as an argument to view the used and available space for the directory. Let’s say I have a directory named mydirectory and I want to view available space for the directory. I need to follow the steps below:

  1. At first open the Ubuntu Terminal.
  2. Type the following command in the command prompt:
    df mydirectory
  3. Now, press the ENTER button.

The output will be like this:Displaying disk space usage for a directory using the df command in linux

Note: Here mydirectory is just a directory name in my machine. It can be whatever you want.

Similar Readings


Example 4: Show Grand Total Available Space Using the “df” Command in Linux

You can also view the grand total available space of your machine. Follow the steps below to do the same:

  1. At first open the Ubuntu Terminal.
  2. Type the following command in the command prompt:
    df --total
  3. Now, press the ENTER button.

You will see at the end of your output there is a new line at the end starting with the word total.Showing grand total used and available space

Example 5: Display File System Types Using the “df” Command in Linux

To view file systems with their types, follow the steps below:

  1. At first open the Ubuntu Terminal.
  2. Type the following command in the command prompt:
    df -T
  3. Now, press the ENTER button.

As you can see, there is an extra column with the heading Type.Printing file system type


Similar Readings


Example 6: Display Specific File System Type Using the “df” Command in Linux

You can print file systems with a specific type using the df command in Linux. For example, if I only want to see ext4 type file system, I need to follow the steps below:

  1. At first open the Ubuntu Terminal.
  2. Type the following command in the command prompt:
    df -T -t ext4

    OR,

    df -Tt ext4

    Note: Using option “-T” isn’t mandatory. I used it so that you can have a clear understanding. Also, putting option “-t” before “-T” would generate an error as the option “-t” needs an argument.

  3. Now, press the ENTER button.

As you can see, there is only ext4 type file system.Printing a specific type of file system using the df command in linux

Example 7: Display File System Excluding Specific File System Type

You can also exclude a specific file system type. For demonstration purposes, I will exclude the tmpfs type file system. Now follow the steps below:

  1. At first open the Ubuntu Terminal.
  2. Type the following command in the command prompt:
    df -T -x tmpfs

    OR,

    df -Tx tmpfs

    Note: Using option “-T” isn’t mandatory. I used it so that you can have a clear understanding. Also, putting option “-x” before “-T” would generate an error as the option “-t” needs an argument.

  3. Now, press the ENTER button.

There is no tmpfs type file system in the output.Showing file system excluding a file system type


Similar Readings


Example 8: Customize Output of the “df” Command

You can customize the output of the df command in Linux. You need to use the double dash option (–), followed by an equal (=) sign and finally a comma-separated list of columns of our interest (‘source‘, ‘fstype‘, ‘itotal‘, ‘iused‘, ‘iavail‘, ‘ipcent‘, ‘size‘, ‘used‘, ‘avail‘, ‘pcent‘, ‘file‘ and ‘target‘ etc). As I want only want to print Filesystem, Avail and Use%, I will use ‘source’,’avail’ and ‘pcent’. Now follow the steps below to do the same:

  1. At first open the Ubuntu Terminal.
  2. Type the following command in the command prompt:
    df --output=source,avail,pcent
  3. Now, press the ENTER button.

Now you can see our customized outputCustomized output of the df command in linux

Example 9: Displaying Inode Information Using the “df” Command in Linux

Every file and directory in a filesystem has an Inode number. This number keeps track of all files and directories within a Linux or Unix-based filesystem. You can print Inode information by following the steps below:

  1. At first open the Ubuntu Terminal.
  2. Type the following command in the command prompt:
    df -i
  3. Now, press the ENTER button.

Now you will get your output in Inode number.Showing Inode information


Similar Readings


Example 10: Show Disk Space Available for a Specific Mount

To print disk space info for a specific mount, you need to provide the name of that mount as an argument. Let’s say I want to find information of the mount “/”. I will follow the steps below:

  1. At first open the Ubuntu Terminal.
  2. Type the following command in the command prompt:
    df /
  3. Now, press the ENTER button.

See, I am only getting the information of mount “/”, nothing else.Displaying disk space information for a specific mount

Example 11: Display Only Grand Total in Human Readable Form

Now, here is another example of combining multiple options of the df command in Linux. I also piped the output of the df command into another command. Let’s say I am only interested in displaying the grand total in a human-readable format. First, I used options “–total” and “-h” and piped the output into the command grep. grep is used to search text based on a pattern. I provided the grep command pattern “total”. So it is only showing the line containing the word total. You can do it yourself by following the steps below:

  1. At first open the Ubuntu Terminal.
  2. Type the following command in the command prompt:
    df --total -h | grep total
  3. Now, press the ENTER button.

Now, you will see the output like this:Only showing grand total space in human readable form using the df command in linux

Conclusion

Hopefully, you have tried all the examples above, and I am pretty sure you have a good grip on the df command in Linux. Eventually, you will be spontaneous and efficient in using the command.


Similar Readings

Rate this post
Walid Al Asad

Hello Everyone! I am Walid Al Asad. Currently, I am working at a tech company named Softeko as a Linux Content Developer Executive. I live in Dhaka, Bangladesh. I have completed my BSc. in Mechanical Engineering from Bangladesh University of Engineering and Technology (BUET). You can find me on LinkedIn, and ResearchGate. Read Full Bio

Leave a Comment