Get 69% Off on Cloud Hosting : Claim Your Offer Now!
The df (Disk Filesystem) command in Linux/Unix is used to check the disk space usage of file systems. It provides details about total disk space, used space, available space, and usage percentage.
This guide covers everything you need to know about using the df command effectively, along with examples.
The basic syntax of the df command is:
df [OPTION]... [FILE]...
If run without any options, df displays disk space usage in blocks for all mounted file systems.
When you execute df without any options, you get an output similar to this:
Filesystem |
1K-blocks |
Used |
Available |
Use% |
Mounted on |
udev |
4,049,376 |
0 |
4,049,376 |
0% |
/dev |
tmpfs |
814,400 |
1,832 |
812,568 |
1% |
/run |
/dev/sda1 |
50,000,000 |
1,234,567 |
48,765,433 |
3% |
/ |
tmpfs |
4,071,984 |
0 |
4,071,984 |
0% |
/dev/shm |
tmpfs |
512,000 |
0 |
512,000 |
0% |
/run/user/1000 |
Column |
Description |
Filesystem |
The name of the disk partition |
1K-blocks |
The total size of the file system in 1K blocks |
Used |
Space already used |
Available |
Free space available |
Use% |
Percentage of disk space used |
Mounted on |
Mount point (the location where the file system is attached) |
To display disk space usage in a more readable format (MB, GB, TB), use the -h option:
df -h
Example Output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 1.2G 48G 3% /
You can use -k, -m, or -h to specify the units:
-k for Kilobytes (default)
-m for Megabytes
-h for Human-readable format
Example (Display in MB):
df -m
To check the type of each file system, use the -T option:
df -T
Example Output:
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda1 ext4 50000000 1234567 48765433 3% /
To check the disk usage of a specific file system or directory, specify its path:
df -h /home
Use the -i option to show inode information instead of disk usage:
df -i
Example Output:
Filesystem Inodes Used Free Use% Mounted on
/dev/sda1 3276800 54321 3222479 2% /
To exclude specific file system types (e.g., tmpfs), use -x:
df -h -x tmpfs
Use df -a to show all file systems, including those with 0 blocks:
df -a
For script automation, use --output to specify columns:
df --output=source,fstype,size,used,avail,pcent,target
Example Output:
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 50G 1.2G 48G 3% /
To check disk usage every 5 seconds:
watch -n 5 df -h
To quickly check partitions with low space:
df -h | awk '$5 > 80 {print "Warning: Disk Usage High on", $6}'
You can use the following script to notify when disk usage exceeds 90%:
#!/bin/bash
THRESHOLD=90
df -h | awk '{if ($5+0 > THRESHOLD) print "Warning: High Disk Usage on", $6}'
The df command is an essential tool for managing disk space in Linux/Unix systems. By using different options, you can monitor disk usage efficiently and prevent storage-related issues. Whether you're a beginner or a system administrator, mastering df will help you maintain a healthy filesystem.
Let’s talk about the future, and make it happen!
By continuing to use and navigate this website, you are agreeing to the use of cookies.
Find out more