Disk Usage Insights
Disk pressure causes failures that look unrelated: MySQL stops, PHP writes fail, uploads break, and services crash. This guide shows a safe workflow to find what is consuming space and what you can clean up.
Quick Summary
- Confirm space and inode usage:
df -hTanddf -ih. - Locate heavy directories:
duandncdu. - Clean safely: logs, caches, package caches, old backups.
- Do not delete database files directly.
Step 1: check space and inodes
disk-usage-check.sh
df -hT
df -ih
If inodes are near 100%, you may have millions of small files (cache, sessions, temp).
Step 2: find the largest directories
Start at filesystem roots that commonly grow:
du-largest-directories.sh
sudo du -xhd1 / | sort -h | tail -n 20
For interactive exploration:
ncdu-root.sh
sudo ncdu /
Step 3: common safe cleanup targets
Journal logs
journald-usage.sh
sudo journalctl --disk-usage
You can reduce retention:
warning
Vacuuming logs deletes history. Do this only if you accept losing older troubleshooting context.
journald-vacuum.sh
sudo journalctl --vacuum-time=14d
sudo journalctl --vacuum-size=500M
Package caches
apt-cache-cleanup.sh
sudo apt clean
sudo apt autoremove -y
Old backups
If backups are local, ensure you have offsite copies before deleting.
find-old-backups.sh
sudo find /backups -type f -mtime +30 -name '*.tar*' -o -name '*.zip' -o -name '*.zst'
WordPress caches
Cache directories are often safe to delete because they can be regenerated, but check the plugin first.
wordress-cache-candidates.sh
sudo du -sh /var/www/html/wp-content/cache 2>/dev/null || true
sudo du -sh /var/www/html/wp-content/*/cache 2>/dev/null || true
Things not to delete blindly
/var/lib/mysqlor/var/lib/mariadb(database data directory).- Live web roots without a restore plan.
- Anything you are not sure about on a shared box.
Next steps
- If disk space is fine but the box is still slow: see
[Disk I/O troubleshooting](./disk-io-troubleshooting).