Monitoring Disk Usage: A Developer's Guide to df and du
Master Linux disk usage monitoring with df and du. Learn how to check filesystem capacity and identify large files to prevent server outages before they occur.

Previously in this course, we covered Advanced Redirection and Pipes to manipulate data streams. Now that you can move and filter data effectively, it’s time to ensure your server doesn't run out of storage space.
Disk exhaustion is a common "silent killer" in production environments. When a server hits 100% disk usage, logs stop writing, databases crash, and applications become unresponsive. In this lesson, we will use df and du to monitor your server's health and maintain operational stability.
Monitoring Filesystem Capacity with df
The df (disk filesystem) command is your first line of defense. It reports the amount of disk space used and available on your mounted filesystems.
When you run df without arguments, the output can be difficult to read because it defaults to 1KB blocks. Use the -h (human-readable) flag to see sizes in KB, MB, or GB.
Bashdf -h
Understanding the Output
The output columns are straightforward but vital for maintenance:
- Filesystem: The device name (e.g.,
/dev/sda1). - Size: Total capacity of the partition.
- Used: Amount of space currently occupied.
- Avail: Remaining space available.
- Use%: The percentage of space used. This is your primary indicator for when to trigger Linux Server Maintenance: Proactive Disk Health Monitoring Guide tasks.
- Mounted on: The directory where the partition is attached.
Pinpointing Large Files with du

If df shows that your disk is nearly full, you need to find what is consuming that space. This is where du (disk usage) comes in. Unlike df, which looks at the whole filesystem, du analyzes the size of specific files and directories.
To find the size of the current directory, use:
Bashdu -sh *
-s: Summary (only show the total for each argument).-h: Human-readable format.*: Matches all files and directories in the current location.
Practical Example: Cleaning the Project Logs
In our ongoing project, we have a /var/log/webapp directory. Let's inspect it to see if our logs are bloating the disk:
Bash# Move to the logs directory cd /var/log/webapp # Check size of all log files du -sh * | sort -h
The sort -h command is a helpful pipe we learned about in previous lessons; it ensures that the largest files appear at the bottom of your output, making them easy to identify.
Hands-on Exercise: Inspecting Your Server
Follow these steps to practice your disk management skills:
- Run
df -hand identify your primary partition (usually mounted at/). What is your currentUse%? - Navigate to your home directory. Run
du -sh *to see which subdirectories are taking up the most space. - Combine
duwithsortto find the largest file in your/var/logfolder (you may needsudoto view some system logs). - Advanced: Use
du -ah | sort -rh | head -n 5to list the top 5 largest files in your current path.
Common Pitfalls
- Ignoring the
-hflag: Withouthuman-readableoutput, you’ll be staring at abstract block counts that are nearly impossible to calculate mentally. Always use-h. - The "Deleted File" Trap: Sometimes, a file is deleted but a process still has it open.
dfwill show the disk as full, butduwon't find the file. If this happens, you must restart the service that is holding the open file handle. - Running
duon root: Runningdu -sh /will attempt to calculate the size of every file on the system, which can be slow and may result in many "Permission Denied" errors. Always target specific directories.
FAQ
Q: What is the difference between df and du?
A: df reports usage based on the filesystem metadata (how much space the partition has). du traverses the directory tree and calculates the size of the actual files it finds.
Q: My disk is 100% full, but du shows only 50% usage. Why?
A: You likely have a large file that was deleted but is still being held by a running process. Use lsof | grep deleted to identify which process is holding that file open and restart it.
Q: Is there a more visual way to see this?
A: Many Linux distributions include ncdu (NCurses Disk Usage), which provides an interactive, navigable interface for your terminal. It is highly recommended for Linux Disk Usage: How to Find and Remove Large Files tasks.
Recap

Maintaining your server requires active monitoring. By using df -h for a high-level view of filesystem health and du -sh for granular inspection of directories, you can identify and resolve storage issues before they impact your users.
Up next: We will explore how to manage system services, allowing you to start, stop, and enable the applications running on your server.
Work with me

VPS Server Setup, Deployment & Hardening
Get your app live on a fast, secure server — properly configured, hardened, and deployment-ready. No more wrestling with the command line.

Custom WordPress Plugin Development
Custom WordPress & WooCommerce plugins built to standard — by the developer behind a plugin with 5,000+ active installs and a SaaS with 10,000+ users.


