df -h shows / at 100%, MySQL stopped and the site errors out. How do I find the biggest directories and free space without deleting something important?
DEV3 Developer Forum
My server disk is 100% full. How do I find what is using the space and clean it safely?
Ask a question
Every post is reviewed first. Usually reviewed within 24 hours.
dev3 ·
0
1 reply
dev3 · Accepted answer
1. Confirm what is full
df -h # space
df -i # inodes (millions of tiny files can exhaust these)
2. Find the big directories (stay on one filesystem with -x):
sudo du -xh / --max-depth=1 2>/dev/null | sort -h | tail
sudo du -xh /var --max-depth=2 2>/dev/null | sort -h | tail
Or the interactive ncdu / if installed.
3. Common culprits and safe fixes
- Logs:
/var/logand app logs. Truncate a huge active log withsudo truncate -s 0 /var/log/nginx/error.log(do notrma file a process still holds open, because the space is not freed until the process restarts). Then set up logrotate. - Journal:
sudo journalctl --vacuum-size=200M. - Package cache:
sudo apt cleanandsudo apt autoremove. - Docker:
docker system df, thendocker system prune(removes stopped containers, dangling images, unused networks). Add-afor unused images, and--volumesonly if you are sure, since volumes may hold databases. - Old kernels,
/var/cache,/tmp, and old release folders from deployments. - MySQL binary logs:
PURGE BINARY LOGS BEFORE NOW() - INTERVAL 7 DAY;or setbinlog_expire_logs_seconds. - Backups kept on the same disk.
- Deleted but still open files:
sudo lsof +L1lists them; restarting the holding service frees the space.
4. Restart services that failed because of the full disk (MySQL, PHP sessions, queue workers) and check for data corruption in the MySQL log.
Prevent it: alert at 80% usage, rotate logs, move uploads or backups to separate storage, and monitor with a simple cron check or your provider's monitoring.
Never run rm -rf on paths you have not listed first, and avoid deleting anything under /var/lib/mysql or /var/lib/docker by hand.
0