Python Monitoring Disk Space with df
The `df` (disk free) command displays the amount of available and used storage space on mounted filesystems. Understanding partition utilization, mount points, and inode capacity (`df -i`) is vital for preventing server outages caused by full disks.
"`df` is like checking the fuel gauge on your car dashboard: it tells you what percentage of your storage tank is full before the engine stalls."
Deep Dive: How It Works
Core Flags: `-h` (human-readable GB/MB), `-T` (show filesystem type e.g. ext4, xfs, apfs), `-i` (inode usage stats), `-x tmpfs` (exclude virtual memory filesystems).
The 100% Inode Trap: A disk can run out of space even with 500GB free if 100% of available inodes are consumed by millions of tiny 1-byte files.
Root Reserve: Linux ext4 filesystems reserve 5% of space by default for root to prevent system lockups.
Syntax Blueprint
df -h # Human-readable disk usage df -hT # Include filesystem type (ext4, xfs) df -i # Inode availability check df -h / # Check root partition only
Use df -h to inspect disk partition capacity and df -i to monitor inode usage.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Deleting a large open log file with `rm` but `df -h` still shows 100% full.Why it happens: If a running process still has the file open, disk blocks are not freed until the process is restarted or file truncated.
How to fix: Truncate the file in place with `: > /var/log/app.log` or restart the holding process.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Check Disk Space on Root Mount
Run `df -h /` and pipe to `head -n 2` to print filesystem headers and root partition stats.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.