Monitoring disk usage is important for maintaining the performance, stability and security of any Linux server. Whether you manage a VPS, dedicated server, or local machine, the du and df commands help you understand how storage is being used and prevent issues such as low disk space or unexpected interruptions.
This guide explains how to use both commands, what their output means, and practical examples for real-world server management.
Table of Contents
Introduction
Disk monitoring helps you avoid full storage issues that can crash applications, prevent database writes, or stop services from running. Linux provides two powerful built-in utilities, ‘df’ and ‘du’, to gather accurate information about disk usage.
What are the du and df Commands?
df (Disk Free)
Displays the available and used disk space across all mounted file systems.
du (Disk Usage)
Shows disk space used by files and directories.
These commands complement each other; df gives a system-wide view, while du helps identify which directories consume the most space.
How to Use the df (Disk Free) Command?
- Check Overall Disk Usage
Run the following command:df
This displays all mounted file systems along with their total size, used space, available space, and usage percentage. It provides a quick system-wide overview to help you identify if any partition is running low on space.
- View Disk Usage in Human-Readable Format
Run:df -h
The -h option converts the output into a human-readable format, showing sizes in MB, GB, or TB, making it easier to understand.
Example Output:
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 23G 25G 48% /
This helps you quickly assess disk usage on each mounted partition.
- Check Inode Usage
Run:df -i
Inodes track files and directories. Even if disk space is available, a server can stop working if it runs out of inodes. This command helps identify inode shortages before they cause service issues.
How to Use the du (Disk Usage) Command?
- Check the Size of a Specific Directory
Run:du -sh /path/to/directory
- -s: Shows summary information only
- -h: Displays output in human-readable format
This helps you quickly see how much space a specific folder consumes.
- Show Total Disk Usage of the Current Directory
Navigate into the directory and run:du -sh
This displays the total size of everything contained in the current directory, useful for quick space checks.
- List Disk Usage of All Subdirectories
Run:du -h /path/to/directory
This shows the size of every file and subfolder, helping you identify which areas consume storage.
- Sort Directory Sizes to Find the Largest Ones
Use:du -h /path/to/directory | sort -hr | head -20
This command sorts directory sizes in descending order and displays the top 20 largest. It is especially helpful when cleaning up a server that’s running out of space.
Practical Examples
- Find the Largest Directories on the Server
du -ah / | sort -rh | head -20
- Check Disk Usage of the /var Directory
du -sh /var/*
- Check Home Directory Space Usage
du -sh /home/*
Tips for Monitoring Disk Usage
- Use df -h regularly to prevent storage from filling up.
- Use du when you need to find which folder is consuming space.
- Automate checks with cron to get alerts when disk usage crosses a threshold.
- Clean unnecessary logs in /var/log/ to free space.
- Use tools like ncdu for interactive disk usage analysis.
Conclusion
The df and du commands are essential tools for monitoring disk usage on Linux servers. While df gives an overview of total disk space, du helps identify which files and directories consume the most storage. Using these commands together guarantees better resource management and helps maintain server performance and reliability.
Our Linux VPS Hosting plans provide dedicated resources and full control for managing applications, files and server capacity.
Want to manage email storage as well? Learn How to manage email disk usage in cPanel