DEV3 Technologies home

DEV3 Developer Forum

My server disk is 100% full. How do I find what is using the space and clean it safely?

DevOps helpSolved0 views
dev3 ·

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?

#linux#disk#troubleshooting

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/log and app logs. Truncate a huge active log with sudo truncate -s 0 /var/log/nginx/error.log (do not rm a 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 clean and sudo apt autoremove.
  • Docker: docker system df, then docker system prune (removes stopped containers, dangling images, unused networks). Add -a for unused images, and --volumes only 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 set binlog_expire_logs_seconds.
  • Backups kept on the same disk.
  • Deleted but still open files: sudo lsof +L1 lists 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

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.