How to check Free Disk Space using df command in Linux
In Linux, we want to report disk space, we use the df
command.
The df
(disk free) command is used for displays information on the utilization of the file system, partition by partition (disk partition is also called disk slicing for managing each region separately) on which the invoking user has appropriate read access.
- If no file is given, the
df
command displays the available space of all mounted file systems. df
command does not show unmounted file systems.
- By default, the
df
command display available space in 1K blocks, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
The general syntax of the df command
df [option]... [file]...
Brief description of options available with the 'df' command.
Options |
Description |
-a, --all |
include pseudo, duplicate, inaccessible file systems |
-B, --block-size=SIZE |
scale sizes by SIZE before printing them |
--direct |
show statistics for a file instead of the mount point |
-h, --human-readable |
print sizes in powers of 1024 |
-H, --si |
print sizes in powers of 1000 |
-i, --inodes |
list inode information instead of block usage |
-k |
like --block-size=1k |
-l, --local |
limit the listing to local file systems |
--total |
elide all entries insignificant to available space, and produce a grand total |
-t, -type=TYPE |
limit listing to file systems of type TYPE |
-x, --exclude-type=TYPE |
limit listing to file systems, not of type TYPE |
-v |
ignored |
--help |
display help and exit |
--version |
output version information and exit |
Example: Use df command in the home directory to know details about root partition.
here in this example, no file is given then by default, df command display available space, used space, and total space of root file system.
using df command it gave us an output so we can see that root partition have this much amount of used memory and this much amount of available memory but what are these number. This number doesn't have any units on it and we can't easily understand what amount of disk space being used and what amount of this space is available so to make it human-readable there is an option with df command called -h stands for human-readable now we are using this option following with df command.
Now after using the -h option following with df
command the output becomes more friendly and readable.
Example: Check the reports of available and used space for any specific folder with option -h.
In this example, there is a directory containing some files. Using df -h studytonight
it displays total size in human-readable form is 9.8GB, 4.6GB used space and remaining space is 4.7GB i.e. 50% of total space.
Example: Display inode (index node) information.
here in this example using -i (inode) option with df command list index node usage information is display instead of block usage. Index information such as owner, permission, location on the disk.
Example: df command with -k (--kilobytes) option
print sizes in 1K blocks instead of 512-byte blocks. This option overrides the environment variable POSIXLY_CORRECT.
There are no changes after using -k cause output is already 1K form.
Example: df command with --total option
using --total option with df command it displays elide all entries insignificant to available space and produce a grand total.
Conclusion
In this tutorial, we covered how to displays information on the utilization of the system using the df command in the Linux operating system with available options and suitable examples.