Reading Time: 4 minutes
In this df command in Linux with Examples tutorial, We will show you different examples and commands we can use with df commands.
Table of Contents
What is df
The df
command in Linux is used to display information about the disk space usage on your system’s filesystems. It provides a summary of available and used disk space for each mounted filesystem, including hard drives, solid-state drives, network storage, and more. The command stands for “disk free.”
The df
command is handy for monitoring disk space usage on your system, helping you determine which filesystems are running low on space and may require attention. You can also use specific options with df
to tailor the output to your needs, such as -h
to display sizes in a more human-readable format or specifying a particular filesystem to check. To learn more about the available options and usage of the df
command, you can refer to its manual page by running:
df command example
The output of the df
command typically includes the following columns:
- Filesystem: This column shows the name of the filesystem or the mount point.
- 1K-blocks: It displays the total size of the filesystem in 1-kilobyte blocks.
- Used: This column shows the amount of space used in the filesystem in 1-kilobyte blocks.
- Available: It displays the amount of space available for use in 1-kilobyte blocks.
- Use%: This column represents the percentage of used space relative to the total space.
- Mounted on: It shows the mount point, which is the directory where the filesystem is attached within the Linux directory hierarchy.
df command in Linux with Examples
$ df
If you specify a filename with df command it will show you the file system it is part of (Mounted ) and the usage of file systems. In this example below we can see file test.txt is mounted on / file system and it also gives you details of / file system.
$ df test.txt
Options with df commands
Options Detail
-a, –all include pseudo, duplicate, inaccessible file systems
-B, –block-size=SIZE scale sizes by SIZE before printing them; e.g.,
‘-BM’ prints sizes in units of 1,048,576 bytes; see SIZE format
-h, –human-readable print sizes in human-readable format (e.g., 1K 234M 2G)
-H, –si likewise, but use powers of 1000 not 1024
-i, –inodes list inode information instead of block usage
-k like –block-size=1K
-l, –local limit listing to local file systems –no-sync do not invoke sync
-P, –portability use the POSIX output format
-t, –type=TYPE limit listing to file systems of type TYPE
-T, –print-type print file system type
-x, –exclude-type=TYPE limit listing to file systems not of type TYPE
`-a` option in `df` command in Linux
If you want to display all file system information use -a flag with df commands. This will include pseudo, duplicate, and inaccessible file systems. If you do not use -a flag it will show only active file systems.
$ df -a
`-h` or `-H` option in `df` command in Linux
If you use -h flag with df it will print sizes in human-readable format (in power of 1024)
If you use -H flag with df it will print sizes in human-readable format (in power of 1000)
$ df -h
$ df -H
`-x` option in `df` command in Linux
If you use -x flag with df command, It will limit listing to file systems not of type TYPE.
In this example, we will exclude “xfs” file system type
$ df -x xfs
`-hP` option in `df` command in Linux
I use -hP almost all the time with df commands as it gives you output in human-readable format so you do to have to convert it to KB or MB. It will display size in GB. You can also use -k flag to see file system in KB.
-m flag can be used to get file system size in MB.
$ df -hP
How to check inode in Linux
`-i` option in `df` command in Linux
If you use -i options you can get inode numbers of file systems which will help you to troubleshoot disk usage etc.
$ df -i
Conclusion
In this tutorial, we have discussed df command in Linux with Examples, If you still have any questions please write in comments or email us.
You can read more Linux Tutorial here.
More on Df commands
du commands Tutorial