If you are a Linux user or an aspirant Linux leaner you might have come across this command the “df” command. If you want to determine the space consumed by a file or a file system then you need to use the Linux df command.
“df” command when added with different other options can be used to determine information about all sorts of disks and not only that one can use this command to do lots of things that we will discuss later.
In this article, we are going to learn all about Linux df Command To Check Disk Space.
OPTION: type the option that’s assigned to that particular work
FILE: name of the file that you want to know the space of
Note: The use of “file” is optional.
Uses of df command in Linux:-
As mentioned earlier df command can do lots of things and in this section, we are going to use this command to do a few things and just witness the aptness of this command.
These commands are sorted in a manner where it is easy for a reader with different knowledge level to extract the juice out of
Note: All the commands that we are going to talk are case sensitive, therefore, you need to keep that in mind.
Before going on this journey, you need to know a few of the basic commands that should on top of your learning bucket list. So, here we go.
1. Ask Linux for guidance:-
Since Linux is a command based platform, therefore, the chances of you getting stuck amid mental chaos are high. So, Linux though of providing its users with a command with which they can ask for help.
Command: df –help
2. Show the Command Manual in Linux:-
If you are new in the world of Linux and its command then it is really beneficial for you to use this command to get the entire command Manual on your screen.
Command: man df
3. Show the Version Number
If you want to see the version number of the df command that’s installed on your computer then you might want to use the “-version” command with the df command to extract the version number.
Command: df –version
If you are a newbie in this field then you need to know these commands first.
4. Check the Space of file system
Simple use of the “df” command can be used to determine a piece of decent information about each filesystem.
They were made to have a quick glance at your disk places as it uses just 1K block sizes. Therefore, If you want to see the amount of disk space that’s left and the amount that’s used then you should use this command.
5. Check in-depth information of your disk
Even though you can extract some information about your disk with the help of the “df” command, but if you need to extract more information about your disk, you need to use “-a” or “–all” command.
Since this command is displaying all the file systems, therefore, it is regarded as a better alternative than the “df” command.
Command: df -a OR df –all
6. Display information in a human-friendly format
As mentioned earlier the “df” command displays the information in just 1K block size. The extracted information with this command is not very readable, therefore, Linux for the sake of its users introduced “-h” or “–human-readable”.
The information extracted by this command will always be larger than that extracted by the “-df” command as the average size of the information in the prior will fluctuate between MBs and GBs.
Command: df -h OR df –human-readable
To extract a complete information guide about your Disk and the availability of the space, you might want to use the “-total” command. The best part about this command is that it has an entire row dedicated to the amount of disk space available and occupied space, namely total.
Command: df –total
8. Get storage information of a particular file
Linux provides its users with an option to get information about a particular file as well. The information will be about the storage available and the storage occupied. To use that one needs to add “/name of the file” after any of the above options.
Note: One should use the human-readable format i.e; -h.
Command: df -h /home
9. Display information about Inodes
Inode in Linux is used to explain the objects of filesystems, such as the files and directory. A “df” command with “-i” or “–inodes” can be used to do that. The information extracted by this command can be very useful to a user as it gives the data about mount-point, inodes, etc.
Command: df -i OR df –inodes.
10. Display information of a particular filesystem type
Linus is blessed to have multiple types of filesystems. Every file system has a distinctive feature assigned to it. Some of the file systems are XFS, EXT3, EXT4, etc. If you want to see the type of the file type then use the “-T” or “–print-type” command.
Command: df -T or df –print-type
11. Show the details in POSIX
POSIX stands for Portable Operating System Interface, in this, the produced output will always support all the system build on Unix. So, in order to implement this command, one needs to add “-P” or “–portability” to the df command.
Command: df -P OR df –portable.
After learning the commands prescribed above in the beginner’s section, it’s time to increase the level by a notch. Here, we are going to discuss some practical uses of the commands discussed. So, here are a few commands that you should learn next.
As mentioned earlier we are going to combine different commands to perform a specific task.
So, we are going to extract the total information of a disk at the same time, we will ensure that the information is user friendly. So, for that, we need to combine “total” and “h” command. Total being used to get the total information and “h” to make it human friendly.
Command: df –total -h /
To display the detailed information of all the partitions in a human-readable format we are going to combine “a” and “h” command, which are “view all” and “human-readable” in a single line of code. You can see the way we combined in the command below.
Command: df -ha OR df –human-readable –all
You can use any of them, the result will be the same.
14. Display Inode information in a human-readable format
Inode as mentioned earlier is used to explain the objects of filesystems, such as the files and directory. So, to display inode information in a human-readable format.
We are going to combine both the command, “-i” and “h” which stands for inode and human-readable respectively.
Command: df -hi OR df –human-readable –inodes OR df -h -i
You can use any of them, the result will be the same.
15. Display POSIX file in a human-readable format
POSIX stands for Portable Operating System Interface, in this, the produced output will always support all the system build on Unix.
If you want to get the POSIX file in a human-readable format you need to combine both the commands, “P” and “h” which stands for POSIX and human-readable respectively.
Commands: df -Ph OR df –portability –human-readable OR df -P -h
16. Exclude a particular file from the output
Linux provides its users with a feature where they can eliminate the result of a particular file system from their output. To do one need to combine “-x” and the file type which is “ext4” in this case, the command “-x” is used to eliminate a particular file system.
Command: df -x ext4 OR df -exclude -type=ext4
So now you won’t be able to see the output of the ext4 filetype. You can even add -h command if you want to make the output in a human-readable format.
17. Include a particular filetype to the output
Linux provides its users with a feature where they can include a particular file system to the output. To do that one needs to combine “-t” and the file type which is “ext4” in this case, the command “-t” is used to include a particular file system.
Command: df -t ext4 OR df type -type=ext4
So now you will be able to see the output of the ext4 filetype. You can even add -h command if you want to make the output in a human-readable format.
After knowing the commands discussed above in the article you will be able to do some tasks and with which you can learn more about Linux and the df command. But in this section, we are going to discuss a few more specific tasks. So, let’s see.
18.Display and Sort Information in POSIX format
The information that we get with the help of the commands discussed above is a hell of a mess.
Therefore, you might want to extract the information and sort it out and at the same time make sure that the information is in a human friendly, that’s the human-readable format. To do that, we are going to encapsulate the “P”, “sort” and “h” command.
Command: df -Ph | sort -nk5.
19. To see a filesystem’s Inode information
To see a filesystem’s Inode information we are going to add, “t”, “h”, “i” commands, and the file type. These commands stand for total info, human-readable, and inode information of the system respectively, and the file type we are choosing here is ext4.
Command: df -hi -t ext4
20. Use 1K block to display Disk Usage
As mentioned earlier the “df” command used to determine a piece of decent information about each filesystem. They were made to have a quick glance at your disk places as it uses just 1K block sizes.
We can obtain the same result with the help of the “-k” command which is a 1K command. The result that you will get after inserting this command is similar to that obtained by the “-h” command.
Command: df -k
21. Display Local FileSystem’s Inode Information
To display the local filesystem’s Inode information we are going to accumulate both the “i” and “-l” command in this code.
Command: df -li OR df –local –inodes
One thing that you should keep in mind that the output will not be very human-readable if you want to change it to that format then just add “-h” to the mix. Then your command will look something like.
Command: df -lih
22. Display a filesystem’s POSIX format
To display your filesystem’s information in Portable Operating System Interface then you need to add a lot of different commands, four to be specific. We are going to add “-P”,”-h”,”-T”,”-t”, and file type, which are Portable, human-readable, check the file type and total info respectively. Your command will look like…
Command: df -Ph -T -t ext4
23. To store the output
Linux allows its users to save output with the help of a very easy command. You need to add df_output to your already existing command. For example, if I want to store the output of my system’s inode information in a human-readable format your command will look like.
Command: df -hil > df_output
24. Show the usage of my disk in powers of 1000
More often than not, you will find your system using MBs and GBs, and its magnitude is represented in the power of 1024.
But if you are someone who wants to use Linux Shell Scripts to integrate disk checking commands, you might want to convert the usage of the disk in powers of 1000.
Command: df -H OR df –si
Linux df command is a really helpful command to check out the disk space and to get the information of stored files and lookout the how much space a file is using. In this post, we collected 25 Linux df command for you.
If you have missed any Linux df command in this post, kindly let us know by putting your comment.