Managing disk space efficiently is crucial for system administrators and developers working on Linux. One of the most essential tools for this task is the df command in Linux. This command allows you to monitor available and used disk space across mounted filesystems, helping you prevent storage-related issues.
In this guide, we’ll explore how to use the df command in Linux, covering its options, use cases, and practical examples to help you manage disk space effectively.
For a step-by-step visual demonstration, watch our YouTube tutorial on the df command in Linux:
1. What is the df Command in Linux?
The df command in Linux provides an overview of your system’s disk space usage. Running it without any options gives you a basic report:
This command displays information such as total space, used space, available space, and filesystem mount points. However, the output may be difficult to interpret due to its default block size representation.
2. Making df Output Human-Readable ✅
By default, the df command in Linux displays sizes in blocks, which may not be intuitive. To make the output more readable, use the -h
(human-readable) option:
✅ Use Case:
If you’re managing a Linux server (such as Rocky Linux) and need a quick overview of disk usage, the -h
option makes it easy to see available space in familiar units like KB, MB, and GB.
3. Checking Disk Space for a Specific Directory ✅
To monitor a particular filesystem, use df command in Linux with a specific directory path. For example, to check the space used by the /home
directory:
✅ Use Case:
If you manage a database server or a system with a dedicated partition for logs (/var/log
), this command ensures critical directories don’t run out of space.
4. Checking Inode Usage with df Command in Linux ✅
Disk space isn’t the only factor affecting your filesystem. If you have millions of small files, you might run out of inodes (file metadata) before disk space. To check inode usage, use:
✅ Use Case:
On web servers hosting thousands of tiny cache files, running out of inodes can cause issues even if there’s available disk space. Checking inode availability helps diagnose such problems.
5. Filtering by Filesystem Type Using df Command in Linux ✅
Linux supports different filesystem types, including ext4
, xfs
, and tmpfs
. To display the filesystem type in your df command in Linux output, use:
If you want to exclude temporary filesystems like tmpfs
, use:
✅ Use Case:
System administrators working with Docker or virtualized environments often exclude tmpfs
or other virtual filesystems for a clearer view of actual storage.
6. Live Disk Space Monitoring with df Command in Linux ✅
For real-time monitoring of disk space usage, pair df command in Linux with the watch
command:
✅ Use Case:
This is useful during large file transfers, software installations, or backups, allowing you to track space consumption live.
7. Using df Command in Linux for Scripting & Automation ✅
System administrators often automate disk space monitoring. To ensure script-friendly output, use the -P
(POSIX-compliant) option:
✅ Use Case:
This format makes it easier to parse disk space data in shell scripts for automated alerts if disk space drops below a critical level.
Frequently Asked Questions (FAQs) About df Command in Linux
1. How do I check disk space in Linux without using df?
You can use the du
(disk usage) command for a directory-specific report:
2. Why does my Linux system show full disk space despite having free space?
You may have run out of inodes (df -i
), or reserved space for the root user may be consuming disk capacity.
3. Can I monitor disk space usage in real-time?
Yes, use:
This provides live updates every 2 seconds.
4. How do I exclude certain filesystems in df output?
Use the -x
option, for example, to exclude tmpfs
:
5. What’s the difference between df and du?
df
shows disk space usage per filesystem.du
shows disk usage per directory or file.
Conclusion
The df command in Linux is an essential tool for managing disk space on Linux. Whether you’re troubleshooting storage issues, monitoring inode usage, or setting up automation for alerts, mastering df command in Linux is crucial for efficient Linux system administration.
For a step-by-step visual guide, check out our YouTube tutorial on the df command in Linux.