Skip to content
STAGE33R

Guides · Operations · 6 steps · reviewed

Linux disk full? How to find what is using the space and clean it safely

A full disk stops databases, breaks logins and corrupts writes. It usually happens slowly: logs, Docker layers, old backups, or an application writing to the root disk because an external disk did not mount.

  1. See which filesystem is full

    Look at Use% and the mount point.

    df -hT -x tmpfs -x devtmpfs
    df -i   # also check inodes
  2. Find the biggest folders

    Descend one level at a time and stay on one filesystem.

    sudo du -xh / --max-depth=1 2>/dev/null | sort -h | tail -n 10
    sudo du -xh /var --max-depth=2 2>/dev/null | sort -h | tail -n 10
  3. Trim the journal and package caches

    Safe and often frees gigabytes.

    sudo journalctl --vacuum-size=300M
    sudo apt-get clean
    sudo apt-get autoremove --purge
  4. Clean Docker without deleting data

    Dangling images and build cache are safe. Do not add the volumes option unless you are sure no volume holds data you need.

    docker system df
    docker image prune -f
    docker builder prune -f
  5. Rotate and compress big logs

    Check which logs grow and that logrotate runs.

    sudo ls -lhS /var/log | head
    sudo logrotate -d /etc/logrotate.conf 2>&1 | tail -n 5
  6. Prevent it from happening again

    Alert before 80 percent, and make sure external disks are in /etc/fstab so apps never write to the root disk by mistake.

    sudo findmnt --verify

Common mistakes

  • Deleting an open log file: the space is not freed until the process restarts (truncate it instead).
  • docker system prune -a --volumes removes data volumes.
  • Ignoring inodes when many tiny files fill the filesystem.

How to undo it

Package caches and images are re-downloaded when needed. Deleted data comes back only from a backup.

Sources

Commands are for Debian and Ubuntu unless noted. Test on a copy first and keep a backup: you are responsible for changes on your own systems.