Check Disk Usage
# Overview of all filesystems
df -h
# Check inode usage (running out of inodes is as bad as disk space)
df -i
# Size of current directory
du -sh .
# Top 10 largest directories
du -h --max-depth=1 / | sort -rh | head -10Find Large Files
# Files over 100 MB
find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null
# Largest files in /var
find /var -type f -exec du -h {} + 2>/dev/null | sort -rh | head -20Common Space Consumers
| Location | Cause | Solution |
|---|---|---|
/var/log/ | Log accumulation | Configure logrotate, clear old logs |
/tmp/ | Temporary files | Clean with tmpreaper or reboot |
/var/lib/docker/ | Docker images/volumes | docker system prune -a |
/var/cache/apt/ | Package cache | sudo apt clean |
/home/*/ | User files | Review and clean up |
Automated Monitoring
Create /usr/local/bin/disk-alert.sh:
#!/bin/bash
THRESHOLD=85
USAGE=$(df / | tail -1 | awk '{print $5}' | tr -d '%')
if [ "$USAGE" -gt "$THRESHOLD" ]; then
echo "WARNING: Disk usage is ${USAGE}% on $(hostname)" | mail -s "Disk Alert" admin@example.com
fichmod +x /usr/local/bin/disk-alert.sh
# Run hourly
echo "0 * * * * root /usr/local/bin/disk-alert.sh" >> /etc/crontabPreventive Measures
- Set up logrotate for all application logs
- Schedule regular cleanup of temporary files
- Use
ncdufor interactive disk usage analysis - Monitor with alerting tools (Netdata, Prometheus)