Managing Disk Space on Your Server
Check Overall Disk Usage
df -h
Shows each partition, total size, used space, available space, and mount point. Watch for any partition above 80% usage.
Find Large Directories
du -sh /* 2>/dev/null | sort -rh | head -20
Interactive Disk Usage Browser — ncdu
apt install ncdu -y
ncdu /
Navigate with arrow keys, press d to delete a file or directory, q to quit.
Common Disk Space Culprits
Old log files:
ls -lh /var/log/
journalctl --disk-usage
journalctl --vacuum-size=500M # Keep only 500 MB of system logs
APT package cache:
apt autoremove -y
apt clean
Docker unused images/containers:
docker system prune -a
Old Linux kernels (Ubuntu):
apt autoremove --purge -y
Monitor Disk Usage Over Time
watch -n 5 df -h
Set Up a Low-Disk Alert
Add this to your crontab to email you when disk usage exceeds 85%:
0 6 * * * df -h | awk '$5+0 > 85 {print}' | mail -s "Disk Alert" you@example.com