This article will help to understand what is the use of df command in Linux and how to use df command with multiple options in Linux/Unix. The 'df' (Disk Free) command in an inbuilt utility to find the available and the disk usage space on Linux servers/storage. This command is mainly used by all the System Admins, as it is one of their main tasks to monitor the server/storage space. Don't confuse with df and du command. Check here " how to use the du command in Linux with examples"
This guide will help you how to use df command in Linux with options and examples. All the below examples are tested on RHEL/CENTOS 7.6
The Global Syntax of df command in Linux:
df [OPTION]... [FILE]...
The following table provides an overview of the options of df command in Linux.
1. How to check the details of disk space used in each file system?
Note: Using 'df' command without any option/parameter will display all the partitions and the usage information of the disk space. The result of the above command contains 6 columns which are explained here below:
Filesystem --> Mount Point Name
1K-blocks --> Available total space counted in 1kB (1000 bytes)
Used --> Used block size
Available --> Free blocks size
Use% --> Usage on percentage-wise
Mounted on --> Show the path of the mounted point
# df -k
Note: Even using the '-k' option also provides the same output as the default 'df' command. Both outputs provide the same data usage of file systems in block size which is measured in 1024 bytes.
2. How to check the information of all the file system disk space?
# df -a
Note: The result of the above command is the same as the previous output, but here the '-a' option will list even all the fake/not-real filesystem along with the real files. As we know, that Linux always creates and populates file systems based on the running functionalities, it is called pseudo files system (means it will always create fake/not-real files based on its currently running system) and it will not appear in the rootfs file system of the distro image. Eg: proc,sysfs,etc.
3. How to check the disk space in Human-Readable format?
# df -h
Note: Using the'-h' option will list all the output in "Human Readable Format". You can see the results of all the disk space of my previous examples measured in bytes, which are difficult to read. You can see this example, it measures all the sizes in GB which is easy to understand. Reading the sizes in MB, GB, TB is much easier than the kB. The '-h' human-readable format used the power of 1024.
# df -H
Note: Using '-H' option will list all the sizes in power of 1000, you can see the difference in the size of disk space of using "df -h and df -H".
4. How to sum up the total of the disk space usage?
# df -h --total
Note: using '--total' along with '-h' will sum up the total disk usage of all the file systems.
5. How to list the Inodes information of all file systems?
# df -i
Note: Using '-i' will list the information about the Inodes of all the filesystem. If you are not sure what is Inode? then (click wiki details)
6. How to list only the local file system?
# df -l
Note: Using the'-l' option will filter all the network/remote based file systems and list only the local-based file system.
7. How to list the file system usage in MB (MegaByte)?
# df -m
Note: Using the '-m' option we can get the output of all the file systems disk space usage in MB (megabytes).
8. How to check the file system type?
# df -T
Note: Using the'-T' option we can get the list of file system types. As you can see types of file systems in the above example's 2nd column "TYPE" as "ext4,tmpfs,ext2".
9. How to check the disk space details of a specific file system type?
# df -t ext4
Note: Using the'-t' option we can filter the output of a specific file system. In this example, I have used the "ext4" file system. You can check it accordingly.
10. How to exclude a particular file system type?
# df -x tmpfs
Note: Using the'-x' option we can exclude any particular type file system from the output list. In this example, I have excluded "tmpfs" file system type from the output. The output can be compared with the previous example. Exclude and without exclude of tmpfs filesystem.
11. How to customize the output with certain columns?
# df -h / --output=size,used
Note: Using '--output[=FIELD_LIST]'with df command you can customize your output with certain fields/columns. Check the example I used here.
# df --help or man help
Note: For any help related to 'df' command you can use the above commands.
I hope this article will help you to understand 'df' commands with examples. Drop me your feedback/comments. If you like this article, kindly share it and it may help others as well.