What's filling up my disk? Finding and freeing space Print

  • 0

A full disk can stop databases, mail and logging, and sometimes the whole server. Here's how to find the cause quickly.

Which filesystem is full?

df -h      # space
df -i      # inodes: millions of tiny files can fill a disk too

What is using the space?

du -xh --max-depth=1 / | sort -h
du -xh --max-depth=1 /var | sort -h

ncdu -x / gives an interactive view if it's installed. The usual suspects: /var/log, database binary logs, old backups, Docker images (docker system df), and package caches.

Space used but no file to be found?

A deleted file that a process still has open keeps using space until the process closes it:

lsof +L1 | sort -k7 -n | tail

Restart or reload that process (often a log writer) to release the space.

Free space safely

  • Don't delete files under /var/lib/mysql or similar by hand. Purge MySQL binary logs with PURGE BINARY LOGS.
  • Truncate a huge active log with truncate -s 0 file.log rather than deleting it.
  • Clean the package cache: dnf clean all or apt-get clean.
  • Then fix the cause: log rotation, backup retention, or an alert at 80% full.

Was this answer helpful?

« Back