How to Free Up Disk Space on Linux: A Practical Guide

Linux doesn’t accumulate junk quite as aggressively as Windows, but leave a system running long enough and it’ll fill up — old kernels, package caches, log files, Docker images, and flatpak runtimes are the usual culprits. Here’s how to find and clear them systematically.

Find Out What’s Using Your Space First

Before deleting anything, get a picture of where the space has gone:

df -h

This shows disk usage per filesystem. Once you know which partition is full, use du to drill into it:

du -sh /* 2>/dev/null | sort -rh | head -20

This lists the top 20 largest directories at the root level. Run it recursively inside whichever directory looks biggest to narrow down the culprit.

If you prefer a visual tool, ncdu is excellent:

sudo apt install ncdu   # Debian/Ubuntu
sudo dnf install ncdu   # Fedora
ncdu /

Navigate with arrow keys and delete files directly from the interface.

Clean Package Cache

Package managers cache downloaded packages, and over time this can grow substantially.

Debian/Ubuntu (apt):

sudo apt clean          # Remove all cached packages
sudo apt autoclean      # Remove only outdated cached packages
sudo apt autoremove     # Remove orphaned dependencies

Fedora/RHEL (dnf):

sudo dnf clean all
sudo dnf autoremove

Arch (pacman):

sudo pacman -Sc         # Remove old package cache
sudo pacman -Rns $(pacman -Qtdq)  # Remove orphans (if any)

Remove Old Kernels

Every kernel update leaves the previous version installed as a fallback. After a few updates, /boot starts to fill up — and it’s usually a small partition.

Ubuntu/Debian: autoremove usually handles this, but you can check:

dpkg --list | grep linux-image

Keep your currently running kernel (uname -r) and at least one previous version. Remove others with:

sudo apt remove linux-image-X.X.X-XX-generic

Fedora:

sudo dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)

This keeps the two most recent kernels and removes the rest.

Clear Log Files

Systemd journals can grow large on busy systems. Check the current size:

journalctl --disk-usage

Trim to a maximum size or time period:

sudo journalctl --vacuum-size=500M
sudo journalctl --vacuum-time=2weeks

Also check /var/log for old rotated log files — anything ending in .gz or a numeric suffix is an archived log that can usually be safely removed if you don’t need it for auditing.

Deal with Docker

If you run Docker, it’s likely one of the biggest consumers of space on your system. Docker accumulates stopped containers, dangling images, unused volumes, and build cache. Clean them all up in one go:

docker system prune -a --volumes

Be careful with the --volumes flag — it removes all unused volumes, which could include data you want to keep. Without it, volumes are left intact.

To check what Docker is using before pruning:

docker system df

Remove Flatpak and Snap Runtimes

Flatpak installs shared runtimes that apps depend on, and old ones linger after updates:

flatpak uninstall --unused

Snap keeps multiple revisions of each installed snap — typically the current and one previous version. Remove old revisions:

snap list --all | awk '/disabled/{print $1, $3}' | while read snapname revision; do sudo snap remove "$snapname" --revision="$revision"; done

Clean Up Your Home Directory

The home directory often hides space usage in less obvious places:

  • ~/.cache — application caches that are safe to clear: rm -rf ~/.cache/*
  • ~/.local/share/Trash — the desktop Trash bin: empty it from your file manager or rm -rf ~/.local/share/Trash/*
  • ~/.npm and ~/.cargo — Node and Rust package caches that grow over time
  • Old virtual environments (venv, .venv) from Python projects you’ve finished

Check for Large Files Anywhere on the System

Sometimes a single large log, core dump, or leftover VM image is the culprit. Find files over 1GB anywhere:

sudo find / -xdev -type f -size +1G 2>/dev/null

The -xdev flag stops it crossing filesystem boundaries, which keeps things sensible on systems with multiple mounts.


Leave a Reply