"Why does my disk show 2GB free in df -h, but I can’t write a log file?" This is a specific error scenario that haunts many developers and sysadmins. You run the command to check free space, see a healthy amount of gigabytes available, yet the application throws a "No space left on device" error. It’s a frustrating disconnect.
df -h is the primary diagnostic tool for assessing filesystem utilization and capacity. It gives you a quick snapshot of your storage health, but it only tells half the story. In my 15 years of troubleshooting Linux servers, I’ve learned that blindly trusting the df output without understanding its underlying mechanics—like reserved blocks or inode exhaustion—leads to hours of wasted time.
This guide goes beyond basic syntax. We will decode what df -h actually means, explore why it often disagrees with du, and provide a practical workflow to find and fix "disk full" errors. By the end, you’ll know how to interpret the data, identify the ghost space problem, and automate monitoring to prevent emergency situations.
Decoding the Output: What Does 'df -h' Actually Mean?
To master df -h, you need to understand what you are looking at. It’s not just a list of numbers; it’s a report on filesystem health. Let’s break down the columns and the flags that control how data is displayed.
Column-by-Column Breakdown of the Output
When you type df -h, you typically see a table with six key columns: Filesystem, Size, Used, Available, Use%, and Mounted on. The "Filesystem" column lists the block device (like /dev/sda1) or network filesystem. "Size" and "Used" are straightforward, but "Available" often surprises users.
You might notice that Available is less than Size - Used. This isn’t a bug; it’s a feature. On ext4 and xfs filesystems, a small percentage of blocks (usually 5% by default) is reserved for the root user. This ensures that even if the disk is "full" for regular users, the root account can still log in and clean up files to fix the issue. Ignoring this reserved block space is a common mistake when calculating true capacity.
Here is a sample output from a standard Ubuntu server using an ext4 filesystem:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 40G 38G 2.1G 95% /
In this example, the disk is nearly full. The "Use%" column is calculated based on the total usable space (Size minus reserved blocks), which is why it hits 95% even if there are still gigabytes "physically" on the disk.
The -h Flag: Human-Readable vs. Other Units
The -h flag stands for "human-readable." It converts byte counts into K, M, or G. However, there is a nuance here that confuses many engineers: Linux typically uses base-2 for memory and block sizes (1024), but df -h labels these as K/M/G, which technically implies base-10 (1000).
For precision, you can use df -H (uppercase H), which explicitly uses base-10 (SI prefixes). Or you can use df -k to force kilobytes (1024 bytes) without auto-scaling. In most operational contexts, df -h is sufficient. The difference between df and df -H is minor for daily tasks, but critical when calculating exact storage costs or capacity planning. I prefer df -h for quick checks because it aligns with how most hardware manufacturers label their drives, even if the underlying math is binary.
Beyond -h: Essential 'df' Command Options for Deep Analysis
df -h is the starting point, but it’s not the only tool in the belt. To truly troubleshoot storage issues, you need to look under the hood with specific flags. This section covers the df command options that reveal hidden problems.
Checking Inode Exhaustion with 'df -i'
A file in Linux is not just data; it’s also metadata stored in an inode. If you run out of inodes, you cannot create new files, even if you have terabytes of free space. This is known as inode exhaustion. It’s a classic "gotcha" that often happens in directories with millions of small files, like /var/mail or cache directories.
To check inode usage, use the -i flag:
df -i /
If the "IUse%" column is at 100%, your filesystem is effectively full, regardless of the block count. In one incident, a web server was down because /var/lib/nginx/cache had millions of tiny thumbnail files, exhausting inodes on a 100GB disk with 80GB free. The fix wasn’t deleting large files; it was removing thousands of small ones.
Filtering Specific Partitions and Filesystem Types
Running df -h on a large server can output a long list of mounted volumes. To focus on a specific area, pass the mount point as an argument. For example, df -h /var will only show the filesystem containing /var. This is crucial for targeted troubleshooting.
You can also filter by filesystem type using the -T flag (to display the type) or -t (to include only specific types). For instance, df -T will show you which partitions are ext4, xfs, or tmpfs. Knowing the filesystem type matters because different types handle reserved blocks and journaling differently. In advanced storage setups like ZFS, you would use zfs pool status instead, as df only sees the top-level mount point and not the underlying pool details.
Troubleshooting Discrepancies: Why 'df' Differs from 'du'
This is the section where most confusion arises. You run df -h, see 5GB free. You run du -sh /var and the total used space adds up to less than 5GB, yet the system says it’s full. Why? The difference between du and df in Linux lies in what they measure. df looks at the filesystem block level, including metadata and reserved space. du looks at the file content level, summing up actual file sizes.
Understanding Reserved Blocks and Root Overhead
As mentioned earlier, ext4 and xfs reserve space for root. du does not account for this. If you have a 100GB disk with 5% reserved, df shows 95GB as usable. du might show 94GB used by files. The missing 1GB isn't "lost"; it’s parked for emergencies.
You can check the reserved block count with tune2fs -l /dev/sda1 for ext4. While you can adjust this percentage, I strongly advise against it unless you have a very specific reason. Reducing the reserved space to 1% can brick your system if it fills up completely, leaving no room for root to log in and fix the issue. In my experience, the 5% default is a sweet spot for most general-purpose servers.
Resolving the 'Ghost Space' Problem (Deleted Open Files)
Here is the most common "ghost space" culprit: deleted but open files. Imagine a log application writing to app.log. You delete the file (rm app.log) to save space. df immediately shows the space as free, right? No. If the application still has the file handle open, the space is not reclaimed until the process closes the file or the system reboots.
This causes df to report the disk as full, while du (which scans the directory tree) shows low usage because the file is no longer visible in the directory. To find these "ghost" files, use lsof:
lsof +L1
This command lists files that have been unlinked (deleted) but are still open. You’ll see entries like java 1234 1w /path/to/deleted.log (deleted). Killing the process or restarting the service will release the space. This is a unique insight often missed in basic tutorials, yet it solves 50% of "mystery full disk" tickets.
Practical Workflow: Finding Large Directories After 'df -h'
Now that you understand the metrics, let’s put them into a practical workflow to find and fix the issue. This is how I approach "find largest directories after df -h" scenarios in a production environment.
Combining 'df' and 'du' for Root Cause Analysis
First, identify the problematic mount point using df -h. Let’s say /var is at 98% capacity. Now, use du to drill down. Start with the top level:
du -h --max-depth=1 /var
This will show which subdirectory is the biggest offender. Is it /var/log? /var/lib/docker? Let’s assume it’s /var/log. Now, go one level deeper:
du -h --max-depth=1 /var/log
You’ll likely see that syslog or nginx-access.log is huge. This is where you apply your fix. For logs, ensure logrotate configuration is working. For /tmp or /var/cache, perform temporary files cleanup to remove stale data. This combination of df (to locate the mount) and du (to locate the directory) is the standard root cause analysis pipeline.
Automating Monitoring with Bash Scripts
Don’t wait for the disk to be full to react. Automate it. Here is a simple bash script that parses df -h output and alerts if usage exceeds 90%. This is a staple for monitor disk usage with df cron setups.
#!/bin/bash
THRESHOLD=90
for fs in $(df -h | awk 'NR>1 && $1 !~ /tmpfs|devtmpfs/ {print $1}'); do
usage=$(df -h $fs | awk 'NR==2 {gsub(/%/,"",$5); print $5}')
if [ "$usage" -ge "$THRESHOLD" ]; then
echo "Alert: $fs is at ${usage}%"
# Add email or webhook notification here
fi
done
Add this to your cron jobs (e.g., hourly) to catch issues before they become outages. For enterprise environments, integrate this logic with Prometheus and Node-Exporter. The node_exporter agent automatically exposes node_disk_used metrics, allowing you to set up Grafana dashboards and alerts without writing custom scripts.
FAQ
Why does 'df -h' show different available space than 'ls -la' or 'du'?
df reports filesystem-level capacity, which includes reserved blocks, metadata overhead, and space held by deleted-but-open files. du sums up file sizes from the directory perspective. If df shows less free space than expected, check for reserved blocks (usually 5%) and deleted open files using lsof. df is authoritative for total capacity; du is for finding specific heavy files.
How to check disk space for a specific mount point?
Use the syntax: df -h [mount_point]. For example, df -h /home shows the disk usage for the partition mounted at /home. If you provide a file path (e.g., df -h /var/log/syslog), df will automatically resolve it to the filesystem containing that file. This is useful when you aren’t sure which partition a directory lives on.
What is the difference between 'df -h' and 'df -H'?
df -h uses base-2 powers (1024) but labels them as K/M/G, which is common in Linux. df -H uses base-10 powers (1000) and strictly uses SI prefixes (KB/MB/GB). Most users prefer -h for consistency with how memory (free) and hardware vendors label capacity. The difference is about 5% (e.g., 1GiB vs 1GB), which is negligible for most operational tasks but matters for precise billing.
Can I use 'df' to check SSD health?
No. df only checks filesystem capacity and utilization. It does not access SMART data or wear levels. To check SSD health (such as write amplification, temperature, or sector errors), use smartctl from the smartmontools package or hdparm. df will not tell you if your drive is failing at the hardware level.
Conclusion
Mastering df -h is just the first step in Linux disk diagnostics. While it’s the go-to command for a quick status check, its limitations—such as reserved blocks and inode counts—require deeper investigation when things go wrong. Remember that df and du measure different things, and "ghost space" from deleted open files is a common source of confusion.
Resolving "disk full" issues often requires moving beyond df to tools like du and lsof. I recommend setting up regular monitoring, such as the bash script or Prometheus metrics outlined above, to prevent emergency situations. By understanding the nuances of filesystem utilization, you’ll spend less time firefighting and more time building.
If you found this guide helpful, download our df & du quick-reference cheat sheet PDF for your next incident. Sign up for our newsletter to receive more advanced Linux troubleshooting guides delivered straight to your inbox.





