Commands

Understanding Your Disk Space Through 'df' Command in Linux

The df command is used for checking disk space in Linux. Learn some of the most common usage of the df command in Linux.

Helder
Helder

It doesn’t matter if you are a system administrator or a regular desktop user, you must know how much disk space you have available or consumed in order to keep things properly rolling on your system.

If you use desktop Linux this can be done through the regular file manager but a Linux user should know his/her command line and get the most of it, right? This is why you need to know and understand a little bit more of the ‘disk format’ or ‘df’ command.

Using df command to check disk space in Linux

Df Command in Linux

Let’s see how can you use the df command to get various kind of disk space information in Linux.

Just ‘df’ to see disk information

The main and plain ‘df’ command will output the entire list of file systems in your Linux setup. To explain what is a file system, we probably would need an entire article, however for now let’s say it is the way some files are arranged in your system.

Screenshot 3 1
A simple ‘df’ will give you entire list of filesystems

This information will probably not be the best in terms of readability, so let’s explore a better version.

Human readable option ‘df -h’

In order to get a ‘human readable’ version of the output (that’s what the ‘h’ stands for) you would do a ‘df -h’.

df -h

This will give you something like this:

Screenshot 4 1
The df -h gives you a better readable version

As you can see, it will list the file systems and use Gigabytes and Megabytes unit to represent space, which is a lot easier to understand and work with.

Listing types for each file system

It might be useful to list the file systems with their correspondent file system type for each one. To do this, you can use the ‘-T’ option:

df -T
Screenshot 5
Listing the type for each file system using the -T option

Check free disk space in Linux with df command

Sometimes you want to know how much disk space is available for a particular folder in your system in the file system where that folder resides, so you can know it by simply using the ‘df’ with the folder you want to know about.

df -h directory_name
Screenshot 6 1
How much space I have available for my Videos folder

This shall not be confused with knowing how much space this folder is actually taking from the system, as this information will not be given by the ‘df’ command but by the ‘du’ (disk usage) command. Still, this df option will actually give you an idea of how much space you have available for that particular folder and in which file system it resides.

Exclude certain type of filesystem

We have seen that ‘df’ will give you plenty of information, however, sometimes less is more, and you might want to exclude few file system types in order to obtain only specific data.

In my previous example, you could see I had a lot of ‘snaps’ installed and each of them is listed separately. They all have the ‘squashfs’ file system type, so if I filter those to NOT be included I will get a more bounded information:

Screenshot 7 1
I get a df output excluding all squashfs file systems

By using the ‘x’ option (exclusion) I can remove file systems types from the output in order to get more specific information.

df -x filesystem_type

List particular filesystem only

On the other hand, let’s say you only want to list certain type of file systems so instead of excluding all those you don’t want you simply list the particular one you need.

There is an option for that which is very simple: just add ‘-t’ and the file system type you wish to list.

df -t filesystem_type
Screenshot 10
listing only ext4 file systems

Wrapping up

As you can see the ‘df’ command is a very useful command you must know in order to be able to obtain more information about your disk space. It’s not just a matter of simply knowing the disk space available but it also gives you plenty of options to know about specific file systems and display the information in different formats.

Of course, as any other command you can see some other options it has by simply running a ‘–help’ option in it:

Screenshot 11
As any other command the –help option will give you all the information of what you can do

Do you think there are other useful options or usages of the df command in Linux? Leave me a comment below and don’t forget to share this article with anyone you think might have a nice use for it.



Join the conversation.