How to Check Disk Space Using DF Command in Linux?

Posted in

How to Check Disk Space Using DF Command in Linux?
maazbinasad

Maaz Bin Asad
Last updated on April 26, 2024

    In a typical Windows machine, it’s easier to check disk space through GUI-based tools. However, in the case of Linux, the scenario is a bit different. While it’s true that there are several file managers in Linux that allow you to check your disk space, the filtering options that they provide are minimal.

    We all know how powerful the Linux Command Line is, and it never fails to amaze us. Even in this case, there are some simple commands that you can run to display the disk usage and space. Moreover, you can use certain filters to get your desired output in a particular format. It’s very important to manage disk spaces in Linux effectively.

    Typically, we allot quite limited disk space for Linux installation. Keeping track of the disk space regularly will help you to make sure that you never run out of disk space while installing your favorite packages.

    In this comprehensive guide, we will discuss the df command that you can leverage to display the utilized disk space as well as the available disk space in your Linux machine. Also, we will highlight various examples of the df command to make sure that you understand all its aspects.

    Please note that you need a Linux-based distribution, access to the command-line interface (terminal), and sudo privileges to use the df command. Also, working with sudo privileges is often risky as you might end up crashing your system.

    So, we always recommend that you use commands carefully while logged in as a root user.

    How to Check Disk Space Using the DF Command in Linux?

    df Command

    You can use the simple df (disk-free) command alone to display a list of all the existing file systems that are available in your Linux machine. $ df

    $ df

    However, you can see that it's quite difficult to read and analyze the entire disk space using this format. Also, it’s important to note that by default, the df command will display the information in terms of a 1 KB block.

    Converting the Output into a Human-Readable Format

    To get a better view of the df command results, we can use the -h ( human-readable ) option along with the df command. Please note that instead of using 1KB blocks, this command displays information in Gigabytes (GB) and Megabytes (MB) blocks.

    After running the df command with the -h flag, you will be able to see an output like the one below:

    $ df -h

    Now, let’s try to understand the different columns of information that this command presents to you. The first column, called “ Filesystem ,” displays the name of each type of drive, including virtual, temporary, and physical hard drives.

    Next is the “ Size ” column, which displays the total size of the corresponding file system. The “Used” field displays the amount of space that has already been used. The “Avail” field tells you the amount of space available, and the “Use” field displays the percentage of used space.

    Finally, the “ Mounted on ” column displays all the existing mount points that can be found on the listed file systems. Please note that the /dev/sda2, sda1, or sda0 are generally related to physical hard drives, /udev refers to any virtual directory, and the tmpfs is created by run command as temporary file systems.

    Displaying Particular File Systems

    We can also display or filter results to show the disk space for particular file systems. By using a simple backslash we can display the disk space for the primary hard drive. $ df -h /dev/sda1 $ df -h /

    $ df -h :dev:sda1

    Listing the Type of File Systems

    To know the type of file system, we can use the -t or -T option along with the df command. For finding the types of all file systems, we can use: $ df -hT

     $ df -hT

    To get the list of all file systems with a particular type, we can use the lower case -t option. $ df -ht ext4

    $ df -ht ext4

    Checking Free Disk Space in a Particular Directory

    Sometimes, you might want to check the amount of free space that might be available within a directory. The df command allows you to do so by just specifying the path of the directory along with the command. $ df -h ~/Documents

     $ df -h ~/Documents

    Please note that this command does not tell you the amount of space that this directory occupies out of the total file system size. It simply tells you how much free space is available in this directory, along with other information.

    Excluding Specific File systems

    Sometimes, you might want to exclude certain types of file systems to shorten the list and remove unnecessary items. You can do so by using the -x option along with the df command. $ df -Th -x tmpfs

     $ df -Th -x tmpfs

    Getting Help

    There are a plethora of options that you can use with the df command to get the desired output. However, it’s not possible to explain each one of them here. You can use the --help option to know more about these options and flags used with the df command. $ df --help

     $ df --help

    Wrapping Up

    In this comprehensive guide, we discussed in detail the disk-free command that you can use to display the overall disk usage and other details regarding the file system. We started with a basic introduction of why we need to keep a check on the disk space regularly and discussed the usage and syntax of the df command.

    Moving ahead, we talked about the use of the -h option to print the output in a human-readable format. We then saw how to display a list of particular file systems by mentioning the path.

    Moreover, we also skimmed through the -t and -T options that allow us to display the types of file systems. Finally, we discussed how to use the -x option to exclude certain file systems from the output.

    Also, you should note that the --help option provides information about any command in detail, and the same applies to the df command as well.

    We hope that this guide helped you understand how you can check the disk space using the df command on your Linux machine efficiently and quickly. If you have any thoughts or queries, feel free to share them with us in the comments section below.

    People are also reading:

    Leave a Comment on this Post

    0 Comments