df — check available disk space
💬 "df Command"
While du shows usage by folder, df shows total, used, and available capacity by mounted filesystem (partition). It is one of the first commands run during server health checks.
Because the default output uses 1K blocks and is hard to read, always add -h in practice.
- Concept: Check disk usage by filesystem. See at a glance which mount point is at risk.
- Left column:
Filesystem— The name of the mounted device (e.g. /dev/vda1) or virtual filesystem (tmpfs). - Right column:
Mounted on— The path where the device is attached. This is where issues actually occur. - Size / Used / Avail: Total / used / remaining capacity. If Avail is close to 0, writes will fail soon.
- Use%: Usage percentage. If it exceeds 90%, review log rotation and cleanup.
Commonly Used Options
| Option | Description |
|---|---|
| -h | Output in human-readable units (K/M/G) |
| -T | Also display the filesystem type (ext4, xfs, tmpfs, etc.) |
| -i | Show inode usage instead of capacity (diagnose file count exhaustion) |
| -x tmpfs | Exclude virtual filesystems such as tmpfs |
| --total | Add a total summary line at the bottom |
3 Essential Command Combinations
df -h— Check per-mount capacity in readable units (most basic)df -hT -x tmpfs -x devtmpfs— View only real disks together with their filesystem typedf -ih /var— Check inode exhaustion when capacity remains but files cannot be created
💬 "Give an example of the process of narrowing down the cause"
Common situations on production servers are organized below in the order they typically occur.
Step 1 · Identify Which Mount Has a Problem
Look at all mounts and find the point with high usage.
df -hT -x tmpfs
Step 2 · Find the Culprit Inside It
Move to the problem mount and sort usage by folder in descending order.
cd /var && du -sh * | sort -h | tail -5
Step 3 · Verify After Cleanup
Clear logs or delete old backups, then check again. If the numbers remain the same after deletion, a process is still holding the file.
df -h /var && lsof +L1 | head
How It Is Used in Practice
1. Capacity Check Before Deployment
Situation — Before deploying a new release, you need to check that the target partition has enough free space.
df -h /var /data && df -hT -x tmpfs
Result — Check whether Avail is sufficiently larger than the release size (e.g. 2G). If usage is 90% or more, stop the deployment and clean up first.
Point — Putting a df check at the beginning of the deployment script can prevent disk shortage incidents.
2. Capacity Remains but File Creation Fails
Situation — Free space is 40%, but new log files cannot be created and "No space left on device" appears.
df -ih /var
Result — If IUse% is 100%, inodes are exhausted. You need to clean up directories that contain many small files.
Point — This is a typical failure missed if you only check capacity (%). Include df -ih in your checks.
Things to Watch Out For
- Even if Avail is 0, 5% reserved blocks remain for root, allowing only the administrator to use it briefly.
- When Use% exceeds 90%, system behavior starts to become unstable. Set up threshold alerts.
- For network filesystems such as NFS, df may appear to hang because responses are slow.
- tmpfs and overlay use memory/images, so they differ from actual disk capacity. Exclude them with -x.
Actual Execution Output
This is the result of checking per-mount capacity and usage in readable units.
!df command execution result: capacity and usage by filesystem
A production server
Source (HTML): https://games.aidebatehub.com/programs/linux/filesystem/df.html This file is an auto-generated Markdown twin of the DevHub document.
AI Knowledge Hub
Visitor Comments