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
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.
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’.
This will give you something like this:
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:
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
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:
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
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:
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.