
Check Disk Space with df and du: Differences and Usage
Ever found yourself staring at a โNo space left on deviceโ error, right in the middle of a deploy or backup? Or watched a Docker container go belly-up because the disk was full (again)? If yes, this post is for you. We’re diving deep into the magical world of disk space investigation with df
and du
, the two open-source command-line tools that should be in every server admin’s toolkit.
Table of Contents
- What Is This Article About and Why Should You Care?
- A Real-World Admin Horror Story
- Why Disk Space Management Is a Big Deal
- How Do
df
anddu
Work? - Use Cases: When to Use
df
vsdu
(Comic Table!) - Step-By-Step Guide: Checking Disk Space Like a Pro
- Mini Glossary (with Real-Talk Definitions)
- Examples & Stories: What to Do (and NOT to Do)
- Common Myths, Beginner Mistakes & Similar Tools
- โUse This Ifโฆโ Decision Flowchart
- Automation, Scripting & Unusual Tricks
- Tales from the Trenches: The Curious Case of the Phantom Log
- Conclusion & Recommendations
What Is This Article About and Why Should You Care?
If you run a VPS, cloud instance, Docker host, or a beefy dedicated server, you need to stay on top of your disk usage. This article is your hands-on, no-nonsense guide to checking disk space fast and correctly using df
and du
โ and understanding when to use which one. Whether you’re surviving a server crunch or just want to keep your next deployment drama-free, this guide has you covered.
A Real-World Admin Horror Story
Imagine: Itโs 2AM. Youโre rolling out a quick hotfix. Suddenly, the deploy script fails. โNo space left on device.โ You scramble. df -h
says youโve got 10GB free. The app is still down. Whatโs going on?! Turns out, a rogue log file in a Docker volume ate up every available inode. Your deploy fails, the logs are silent, and the client is calling. This is why knowing when and how to use df
vs du
is more than just a party trick.
Why Disk Space Management Is a Big Deal
- Downtime. Full disks can cause containers, VMs, even the entire host to go offline or crash in weird ways.
- Silent Failures. Many apps just stop writing logs or data, and you donโt notice until itโs too late.
- Performance. Disk nearly full? Youโll see I/O stalls, high load, and slow restarts.
- Security. Attackers love filling up disks to disable logging or cause chaos.
Knowing where your space went is the first step to fixing (and preventing) all of this.
How Do df
and du
Work?
How df
Works: The Big Picture
- What:
df
(โdisk freeโ) shows you the total and available space on each mounted filesystem (think: partitions, volumes, Docker overlay, etc). - How: It asks the kernel for the stats โ not your files! โ so itโs super fast and gives a high-level summary.
- Bonus: Shows inodes (the โslotsโ for files, which can fill up even if you have bytes free).
How du
Works: The Detective
- What:
du
(โdisk usageโ) shows you how much space is used by files and directories (not partitions), starting from a location you choose. - How: It walks the actual directory tree, summing up the size of every file and subdirectory. This takes more time but tells you where the space is going.
- Bonus: Can be filtered, sorted, and customized to quickly find the biggest offenders.
How to Set Up (Fast & Easy)
- Good news: Both
df
anddu
are built into every Unix-like OS (Linux, BSD, macOS). No install needed. Just open your terminal and go! - For Windows servers, use Sysinternals DU or the
fsutil
command for rough equivalents.
Use Cases: When to Use df
vs du
(Comic Table!)
Letโs imagine df
and du
as two quirky detectives:
Scenario | df : The Helicopter Pilot 👀 |
du : The Magnifying Glass 🔍 |
---|---|---|
โAm I running out of disk space?โ | YES! Instantly shows you all filesystems, usage, and free space. | Not really. Shows only what you ask it toโฆ |
โWhatโs eating all the space in /var?โ | Will tell you if /varโs partition is nearly full, but not why. | YES! Pinpoints which folder or file is the culprit. |
โAre my Docker volumes or tmpfs full?โ | YES! Shows special mounts and overlay filesystems. | Needs a path and can be slow if the tree is massive. |
โHow many inodes are left?โ | YES! Try df -i |
Nope. |
โCan I script it?โ | Sure, but limited granularity. | YES! Parse output for automation, file cleanup, etc. |
TL;DR: df
is your โhow full is my disk?โ tool. du
is your โwhatโs filling it up?โ tool.
Step-By-Step Guide: Checking Disk Space Like a Pro
Step 1: Check Overall Disk Usage
df -h
- -h = human-readable (GB, MB, etc.)
- Shows all mounted filesystems and their usage
Step 2: Check Inode Usage (for sneaky problems)
df -i
- Shows number of inodes (file โslotsโ) used/free
- Essential for servers with millions of tiny files (think: mail queues, logs)
Step 3: Find Space Hogs with du
du -h --max-depth=1 /var
- –max-depth=1 means just the top level of /var (or any dir)
- Sort to find the worst offenders:
du -h --max-depth=1 /var | sort -hr | head -n 10
Step 4: Drill Down Further
du -h --max-depth=1 /var/log | sort -hr
- Keep drilling until you find the monster files!
Step 5: Clean Up Safely
- Delete or rotate logs, clear caches, or move old backups off the server.
- Pro tip: After deleting big files, check if theyโre still open with
lsof | grep deleted
Step 6: (Optional) Automate It!
# Quick script to email you when disk is over 90% df -h | awk '$5+0 > 90 {print $0}' | mail -s "Disk Space Warning" you@example.com
Mini Glossary (with Real-Talk Definitions)
- Filesystem: The way your OS organizes and stores files. Think: a bookshelf (not the books themselves).
- Partition: A chunk of your disk, like a shelf on that bookshelf.
- Inode: The โcardโ for each book (file): tracks its name, location, permissions, etc. Run out of inodes? Canโt make new files, even with bytes free!
- Mount Point: Where a filesystem โappearsโ in your directory tree (e.g.,
/home
,/var
). - Block Size: The size of each chunk of storage on disk. Small files can waste space if block size is big.
- tmpfs: A filesystem in RAM. Fast, but data vanishes on reboot.
Examples & Stories: What to Do (and NOT to Do)
- Good: Use
df -h
before every deploy or update. Catch full disks before they bite. - Bad: Only using
du
in/
(root) โ it can take ages and may time out on big servers. - Donโt: Delete files you donโt understand. Some files (e.g., database sockets, active logs) are critical for apps.
- Do: Check for open-but-deleted files with
lsof | grep deleted
โ they can eat up space until the process restarts. - Advanced: Use
ncdu
(see below) for a fast, interactive disk usage browser.
Common Myths, Beginner Mistakes & Similar Tools
- Myth: โIf
df
says I have space, Iโm good.โ
Fact: You can run out of inodes or fill up a partition even if the disk as a whole has free space. - Mistake: Trusting
du
anddf
to always match.
Reality: They measure different things!df
measures filesystem blocks;du
measures file sizes. Sparse files, open-but-deleted files, and mount overlays can cause differences. - Similar Tools:
โUse This Ifโฆโ Decision Flowchart
Letโs make this fun. Imagine your disk is filling up. What should you use?
Is my server running out of space? | v Run: df -h | |---> Disk full? (YES) | | | v | Which partition or mount? | | | v | Run: du -h --max-depth=1| | | v | Spot the biggest hogs and clean up! | |---> Disk not full? (NO) | | | v | Relax, but maybe set up monitoring.
Bonus: If you want to automate all this, set up a cron job with df
and du
outputs piped to email or logs!
Automation, Scripting & Unusual Tricks
- Automated Monitoring: Use
df
incron
to alert when disk usage >80%:
0 * * * * df -h | awk '$5+0 > 80 {print $0}' | mail -s "Disk Space Alert" admin@yourdomain.com
- Cleanup Script: Find and delete log files older than 30 days:
find /var/log -type f -mtime +30 -print -delete
- Show Top 10 Space Hogs in /home:
du -h /home/* | sort -hr | head -n 10
- Find Open-but-Deleted Files (the โZombieโ Problem):
lsof | grep deleted
Unconventional Usage
- Check space used by Docker volumes:
sudo du -sh /var/lib/docker/volumes/*
- Track growth over time by logging
df
anddu
output daily for audit/compliance.
Interesting Fact
The difference between du
and df
can be huge on filesystems with sparse files (like VM images). A 100GB sparse file might show 100GB in du
, but only use 2GB on disk!
Tales from the Trenches: The Curious Case of the Phantom Log
Once, on a late-night shift, a server was โout of spaceโ but df -h
swore we had 15GB free. du
found nothing big. Turns out, a huge log file was deleted (rm
โd), but the process writing to it never closed it. The disk space was still โheldโ by the process, invisible to du
! Only lsof | grep deleted
revealed the culprit. A quick service restart was all it took to release the space. Moral: When in doubt, check for zombie files!
Conclusion & Recommendations
- Use
df
for a quick, high-level view. Itโs your first responder, your โis the house on fire?โ tool. - Use
du
to dig deep and find out whatโs hogging the space. Itโs your surgical scalpel. - Automate both for peace of mind. Donโt wait for 2AM errors โ set up smart alerts and cleanup scripts.
- Want more control? Consider upgrading your infrastructure. For robust, reliable hosting, check out VPS or dedicated servers with plenty of disk space and monitoring built in.
- Bonus: Try tools like ncdu for interactive disk space browsing, or diskus for lightning-fast summaries.
Final Takeaway: Mastering df
and du
is the difference between calmly fixing a problem and scrambling through a disaster. Donโt be that admin โ check your disk space regularly, automate alerts, and always have your favorite disk tools at your fingertips! ๐

This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.