Disk space exhaustion is one of the most common causes of hosting downtime. Your web server stops accepting uploads, databases refuse to write new records, and email queues grind to a halt. As a hosting administrator or site owner, knowing how to check disk usage on Linux is fundamental to preventing these failures before they impact your users.
This guide walks you through the practical commands and tools for monitoring disk space on Linux servers, from basic checks to identifying exactly which directories are consuming storage. Every command is explained with real examples you can run immediately on your VPS, dedicated server, or shared hosting SSH access.
Step 1: Check Overall Disk Usage with df
The df command (disk free) shows filesystem-level disk usage across all mounted partitions. This is your first-line diagnostic tool when investigating storage problems.
Run the Basic df Command
Log into your server via SSH and run:
df -h
The -h flag displays sizes in human-readable format (gigabytes, megabytes) instead of raw block counts. You'll see output similar to:
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 50G 38G 10G 80% /
/dev/vdb1 100G 45G 50G 48% /home
tmpfs 2.0G 1.2M 2.0G 1% /run
Each line represents a mounted filesystem. The key columns are:
- Filesystem: The device or partition name
- Size: Total capacity
- Used: Space currently occupied
- Avail: Space still available
- Use%: Percentage consumed
- Mounted on: Where this filesystem is accessible in your directory tree
Focus on Critical Partitions
Pay closest attention to:
- / (root partition): Where the operating system, web server configs, and application code typically live
- /home: User directories, often where website files and email reside on cPanel servers
- /var: Log files, databases, and mail queues usually grow here
If any partition shows 90% or higher usage, immediate action is required. Above 95%, many applications will start failing.
Filter Specific Filesystems
To check only real disk partitions and exclude temporary filesystems:
df -h -x tmpfs -x devtmpfs
This removes memory-based filesystems from the output, giving you a cleaner view of actual storage devices.
Step 2: Identify Large Directories with du
Once df shows a partition is filling up, you need du (disk usage) to find which directories are responsible. The du command scans directories and reports their total size including all subdirectories.
Scan the Root Directory
To see the size of each top-level directory:
sudo du -sh /*
Breakdown of flags:
-s: Summarize; show only the total for each argument-h: Human-readable sizes/*: Check each directory under root
You need sudo because many system directories require elevated permissions to read.
Output example:
50M /bin
120G /home
4.5G /usr
25G /var
This immediately tells you /home and /var are the largest consumers.
Drill Down into Problem Directories
Once you identify a large directory, investigate its subdirectories:
sudo du -sh /var/*
For web hosting servers, you'll typically find:
15G /var/log
8G /var/mail
2G /var/lib
Continue drilling down:
sudo du -sh /var/log/*
Sort by Size
To see directories sorted from largest to smallest:
sudo du -h /var | sort -rh | head -20
This scans /var, sorts by size in reverse order, and shows the top 20 entries. The -r flag reverses the sort (largest first) and -h tells sort to understand human-readable sizes.
Step 3: Find Large Files Quickly
Sometimes a single large file is the culprit. Use find to locate files above a certain size threshold.
Search for Files Over 1GB
sudo find /var -type f -size +1G -exec ls -lh {} \; 2>/dev/null
Breaking this down:
find /var: Search within /var-type f: Only files (not directories)-size +1G: Larger than 1 gigabyte-exec ls -lh {} \;: Display each result with human-readable size2>/dev/null: Suppress permission denied errors
Common large files on hosting servers:
- Log files:
/var/log/apache2/access.log,/var/log/mysql/mysql.log - Database dumps: Backup files in
/homeor/var/backups - Email mailboxes: Large IMAP folders in
/var/mailor/home/user/mail - Abandoned uploads: Files in
/tmpor web server upload directories
List the Top 20 Largest Files
For a comprehensive view:
sudo find /home -type f -printf "%s %p\n" | sort -rn | head -20 | awk '{size=$1/1024/1024; printf "%.2fMB %s\n", size, $2}'
This searches /home, sorts files by size, and formats the output showing sizes in megabytes.
Step 4: Install and Use ncdu for Interactive Exploration
While du is powerful, ncdu (NCurses Disk Usage) provides an interactive, visual interface that's much faster for exploring directory trees.
Install ncdu
On Debian/Ubuntu:
sudo apt update
sudo apt install ncdu
On CentOS/AlmaLinux/RHEL:
sudo yum install ncdu
or
sudo dnf install ncdu
Run ncdu
Scan a directory:
sudo ncdu /var
After scanning completes, you'll see an interactive interface where you can:
- Arrow keys: Navigate up and down through directories
- Enter: Drill into a subdirectory
- d: Delete a file or directory (use with extreme caution)
- q: Quit
The display shows each directory's size as both absolute value and percentage of parent. This makes it trivial to spot which subdirectories are consuming the most space.
Save ncdu Results for Later
Scan a large directory tree and export the results:
sudo ncdu -o /root/var-scan.json /var
Later, load and browse without rescanning:
ncdu -f /root/var-scan.json
This is useful when the initial scan takes a long time on servers with millions of files.
Step 5: Check Inode Usage
Disk space isn't the only constraint. Linux filesystems also have a limited number of inodes—data structures that store file metadata. You can run out of inodes even when disk space remains available.
Display Inode Usage
df -i
Output:
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/vda1 3276800 425000 2851800 14% /
/dev/vdb1 6553600 6500000 53600 99% /home
If IUse% approaches 100%, you cannot create new files even if gigabytes of space remain. This commonly happens with:
- Email servers: Millions of small message files
- Cache directories: Countless small cache entries
- Session directories: Accumulated PHP or application session files
Find Directories with Many Files
To locate directories with the most files:
sudo find /home -type d -exec sh -c 'echo "$(find "{}" -maxdepth 1 -type f | wc -l) {}"' \; | sort -rn | head -20
This is slow on large filesystems but reveals directories with tens of thousands of files that may be exhausting inodes.
Step 6: Automate Monitoring with Scripts
Manual checks are reactive. Set up automated monitoring to catch problems before they cause outages.
Create a Simple Alert Script
Create /usr/local/bin/check-disk.sh:
#!/bin/bash
THRESHOLD=85
EMAIL="[email protected]"
df -h | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
do
usage=$(echo $output | awk '{print $1}' | sed 's/%//g')
partition=$(echo $output | awk '{print $2}')
if [ $usage -ge $THRESHOLD ]; then
echo "Disk usage alert: $partition is ${usage}% full" | mail -s "Disk Space Alert: $partition" $EMAIL
fi
done
Make it executable:
sudo chmod +x /usr/local/bin/check-disk.sh
Schedule with Cron
Add a cron job to run the check every 6 hours:
sudo crontab -e
Add this line:
0 */6 * * * /usr/local/bin/check-disk.sh
Ensure your server has a working mail system configured (most cPanel and VPS setups include this by default).
Step 7: Clean Up Common Space Hogs
Once you've identified what's consuming space, take action.
Rotate and Compress Logs
Logs are the most common disk space consumer. Check if logrotate is configured:
ls /etc/logrotate.d/
Manually rotate logs immediately:
sudo logrotate -f /etc/logrotate.conf
For Apache/Nginx access logs that aren't needed for analysis, you can safely truncate:
sudo truncate -s 0 /var/log/apache2/access.log
Remove Old Package Caches
On Debian/Ubuntu:
sudo apt clean
sudo apt autoclean
sudo apt autoremove
On CentOS/RHEL:
sudo yum clean all
Clear Temporary Files
Safely remove files older than 10 days from temp directories:
sudo find /tmp -type f -mtime +10 -delete
sudo find /var/tmp -type f -mtime +10 -delete
Audit Backup Files
Backups are essential but shouldn't live indefinitely on production servers. Review:
sudo find /home -name '*.tar.gz' -o -name '*.sql.gz' -o -name '*.zip' | xargs ls -lh
Move old backups to external storage or delete them after confirming newer backups exist.
Practical Checklist: Daily Disk Usage Workflow
For hosting administrators, this is a reliable routine:
- Morning check: Run
df -hto verify all partitions are under 80% usage - Weekly deep scan: Use
ncdu /varandncdu /hometo spot growing directories - Monitor inodes: Run
df -iweekly on high-traffic servers - Review alerts: Check automated monitoring emails immediately
- Rotate logs: Verify logrotate is running successfully (check
/var/lib/logrotate/status) - Audit backups: Monthly review of backup retention policies
Document baseline sizes for key directories so you can spot anomalies quickly.
Conclusion
Checking disk usage on Linux doesn't require specialized monitoring software or complex dashboards. The built-in tools—df, du, find, and ncdu—give you complete visibility into storage consumption on any server. The key is building a regular workflow: quick checks with df, deep investigation with ncdu, and automated monitoring to catch problems early. Master these commands, set up basic alerting, and you'll prevent the vast majority of disk-related hosting outages before they impact your users. Start with the df -h command today and work through each step—you'll have complete disk visibility within an hour.
