How to Check Disk Usage on Linux Server - Complete Guide
Are you wondering how to check disk usage on your Linux server? Need to monitor disk space and identify which directories are consuming the most storage automatically? This comprehensive guide shows you multiple methods to check disk usa...
How to Check Disk Usage on Linux Server - Complete Guide
Are you wondering how to check disk usage on your Linux server? Need to monitor disk space and identify which directories are consuming the most storage automatically? This comprehensive guide shows you multiple methods to check disk usage, track storage consumption over time, identify space-consuming directories, and prevent disk space exhaustion on your Linux server.
Why Monitoring Disk Usage Matters
Monitoring disk usage on your Linux server is critical for preventing storage exhaustion, maintaining system performance, and planning capacity upgrades. When disk space runs out, applications can crash, system logs can't be written, and critical operations may fail. Regular disk usage monitoring helps identify space-consuming files and directories, plan storage expansion, and prevent costly downtime incidents.
Method 1: Check Disk Usage with df Command
The df (disk free) command shows disk space usage for all mounted filesystems. This is the quickest way to see overall disk usage across your system.
Basic Disk Usage Check
To see disk usage for all filesystems:
# Check disk usage in human-readable format
df -h
# Check disk usage in megabytes
df -m
# Check disk usage in gigabytes
df -g
# Show filesystem types
df -hT
This command displays:
- Filesystem name
- Total size
- Used space
- Available space
- Usage percentage
- Mount point
Check Specific Filesystem
To check a specific filesystem:
# Check root filesystem
df -h /
# Check specific partition
df -h /dev/sda1
# Check multiple filesystems
df -h / /home /var
Show Inode Usage
Inodes can also run out even if disk space is available:
# Show inode usage
df -i
# Show inode usage in human-readable format
df -ih
Method 2: Check Directory Sizes with du Command
The du (disk usage) command shows disk usage for specific directories and files. This helps identify which directories consume the most space.
Check Directory Size
To see size of a specific directory:
# Check directory size
du -h /path/to/directory
# Check directory size with summary
du -sh /path/to/directory
# Check multiple directories
du -sh /home /var /tmp
Find Largest Directories
To identify space-consuming directories:
# Find largest directories in root
du -h --max-depth=1 / | sort -rh | head -10
# Find largest directories in home
du -h --max-depth=1 /home | sort -rh | head -10
# Find largest directories system-wide
du -h --max-depth=2 / | sort -rh | head -20
Find Largest Files
To find the largest files:
# Find largest files in directory
find /path/to/directory -type f -exec du -h {} + | sort -rh | head -10
# Find files larger than 100MB
find / -type f -size +100M -exec du -h {} + | sort -rh
Method 3: Automated Disk Usage Monitoring with Zuzia.app
Manually checking disk usage works for occasional monitoring, but for production servers, you need automated monitoring that alerts you immediately when disk usage exceeds thresholds. Zuzia.app provides comprehensive disk usage monitoring through scheduled command execution.
Setting Up Automated Disk Usage Monitoring
-
Add Scheduled Task in Zuzia.app Dashboard
- Navigate to your server in Zuzia.app
- Click "Add Scheduled Task"
- Choose "Command Execution" as the task type
-
Configure Disk Usage Check Command
- Enter command:
df -h - Set execution frequency: Every hour for active monitoring
- Configure alert conditions: Alert when disk usage exceeds 80% or 90%
- Set up thresholds for different filesystems
- Enter command:
-
Set Up Notifications
- Choose notification channels (email, webhook, Slack, etc.)
- Configure alert thresholds (e.g., warning at 80%, critical at 90%)
- Set up escalation rules for high disk usage
- Configure automatic cleanup actions when disk is critically full
Monitor Specific Filesystems
For critical filesystems, create dedicated monitoring tasks:
# Monitor root filesystem
df -h /
# Monitor data partition
df -h /data
# Monitor log directory
df -h /var/log
Track Disk Usage Trends
Track disk usage over time to identify growth patterns:
# Save disk usage with timestamp
echo "$(date): $(df -h / | awk 'NR==2 {print $5}')" >> /tmp/disk-usage.log
# Check disk usage percentage
df -h / | awk 'NR==2 {print $5}'
Zuzia.app stores all command outputs in its database, allowing you to track disk usage trends over time and identify patterns in storage consumption.
Method 4: Advanced Disk Usage Monitoring Techniques
Monitor Disk Usage Growth
To track how disk usage changes over time:
# Save current disk usage
df -h > /tmp/disk-usage-$(date +%Y%m%d).txt
# Compare with previous snapshot
diff /tmp/disk-usage-old.txt /tmp/disk-usage-new.txt
Find Files Modified Recently
Large recently modified files might indicate issues:
# Find large files modified in last 24 hours
find / -type f -mtime -1 -size +100M -exec ls -lh {} \;
# Find large files modified in last week
find / -type f -mtime -7 -size +500M -exec du -h {} +
Check for Log File Growth
Log files can consume significant space:
# Check log directory size
du -sh /var/log
# Find largest log files
find /var/log -type f -exec du -h {} + | sort -rh | head -10
# Check for rotated logs
ls -lh /var/log/*.log.*
Real-World Use Cases for Disk Usage Monitoring
Web Server Disk Monitoring
For web servers:
# Monitor web root directory
du -sh /var/www
# Monitor log directory
du -sh /var/log/nginx
# Check for large uploads
find /var/www/uploads -type f -size +100M
Database Server Disk Monitoring
For database servers:
# Monitor database directory
du -sh /var/lib/mysql
# Check database file sizes
du -sh /var/lib/mysql/*/
# Monitor database logs
du -sh /var/log/mysql
Application Server Disk Monitoring
For application servers:
# Monitor application directory
du -sh /opt/application
# Check for large temporary files
find /tmp -type f -size +100M
# Monitor cache directories
du -sh /var/cache
Best Practices for Disk Usage Monitoring
1. Monitor Disk Usage Regularly
Check disk usage every hour for active monitoring. For less critical systems, every 6-12 hours is sufficient. Use Zuzia.app automated monitoring to check disk usage continuously without manual intervention.
2. Set Appropriate Alert Thresholds
Configure alerts at different levels:
- Warning: 70-80% disk usage
- Critical: 85-90% disk usage
- Emergency: 95%+ disk usage
3. Monitor Multiple Filesystems
Set up separate monitoring for different filesystems (/, /home, /var, /tmp) with appropriate thresholds for each.
4. Track Disk Usage Trends
Use Zuzia.app's historical data to identify patterns. Disk usage that increases gradually over time helps with capacity planning.
5. Monitor Inode Usage
Don't forget to monitor inode usage. A filesystem can run out of inodes even if disk space is available.
Troubleshooting Common Disk Usage Issues
Disk Usage Too High
If disk usage is high:
- Identify largest directories:
du -h --max-depth=1 / | sort -rh | head -10 - Find largest files:
find / -type f -size +100M -exec du -h {} + | sort -rh - Check log files:
du -sh /var/log/* - Clean up temporary files:
rm -rf /tmp/*
Disk Filling Up Quickly
If disk is filling up quickly:
- Check for large recently modified files:
find / -type f -mtime -1 -size +100M - Monitor specific directories:
watch -n 60 'du -sh /var/log' - Check for log rotation issues
- Investigate application behavior
Inode Exhaustion
If inodes are exhausted:
# Check inode usage
df -i
# Find directories with many files
find / -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -rn
FAQ: Common Questions About Checking Disk Usage
How often should I check disk usage?
We recommend checking disk usage every hour for active monitoring. For less critical systems, every 6-12 hours is sufficient. Use Zuzia.app automated monitoring to check disk usage continuously without manual intervention.
What if disk usage is high?
You'll receive alerts when disk usage exceeds thresholds through Zuzia.app. You can then investigate which directories or files are consuming space using du -h --max-depth=1 / | sort -rh | head -10 and take appropriate action, such as cleaning up logs, removing temporary files, or expanding storage.
Can I monitor multiple partitions?
Yes, the df -h command shows all mounted filesystems. You can set separate thresholds for each partition in Zuzia.app if needed. This allows you to monitor /, /home, /var, and other partitions independently.
How do I find which directories are using the most space?
Use du -h --max-depth=1 / | sort -rh | head -10 to find the largest directories. Increase --max-depth to see subdirectories. Use Zuzia.app to track directory sizes over time and identify growth patterns.
What's the difference between df and du?
df shows filesystem-level disk usage (all filesystems), while du shows directory-level disk usage (specific directories). Use df for overall disk space and du for identifying space-consuming directories.
How can I monitor disk usage across multiple servers?
Zuzia.app allows you to add multiple servers and monitor disk usage across all of them simultaneously. Each server executes commands independently, and all results are stored in Zuzia.app's database for centralized monitoring and analysis.
Does Zuzia.app use AI to analyze disk usage patterns?
Yes, if you have Zuzia.app's full package, AI analysis is enabled. The AI can detect patterns in disk usage growth, predict when disks will fill up, identify unusual storage consumption, and suggest cleanup actions based on historical disk usage data and machine learning algorithms.