$linuxjunkies
>

How to Free Up Disk Space on Linux

Recover gigabytes on any Linux system by clearing package caches, trimming the systemd journal, removing old kernels, and hunting large files with ncdu.

BeginnerUbuntuDebianFedoraArch9 min readUpdated May 26, 2026

Before you start

  • sudo or root access on the target system
  • Basic comfort running commands in a terminal
  • A backup or snapshot recommended before removing kernels on production systems

A full disk can bring a Linux system to its knees — package installs fail, logs stop rotating, and databases crash. Before you reach for a bigger drive, there's usually several gigabytes recoverable in minutes. This guide covers the most effective targets: package caches, old kernels, systemd journal bloat, large files, and orphaned packages.

Find What's Actually Using Space

Don't guess — measure first. The classic tool is du, but ncdu (NCurses Disk Usage) gives you an interactive view that's much faster to navigate.

Install ncdu

# Debian / Ubuntu
sudo apt install ncdu

# Fedora / RHEL family
sudo dnf install ncdu

# Arch
sudo pacman -S ncdu

Scan your filesystem

# Scan from root, skip other filesystems (NFS, tmpfs, etc.)
sudo ncdu -x /

Use the arrow keys to drill down and press d to delete a selected item directly. Press ? for help. Focus your attention on /var, /home, and /usr — those are the usual culprits.

Quick du one-liners

# Top 20 largest directories under /
sudo du -ahx / 2>/dev/null | sort -rh | head -20

# Size of each top-level directory
sudo du -hx --max-depth=1 / 2>/dev/null | sort -rh

Clean Package Caches

Every package manager caches downloaded archives. On an active system, this cache can easily exceed 2–5 GB.

apt (Debian / Ubuntu)

# Show how much the cache holds
sudo du -sh /var/cache/apt/archives/

# Remove cached packages that are no longer installable (safe)
sudo apt autoclean

# Remove ALL cached packages (frees more space; packages re-downloaded if needed)
sudo apt clean

dnf (Fedora / RHEL / Rocky)

# Show cache size
sudo du -sh /var/cache/dnf/

# Remove all cached data
sudo dnf clean all

pacman (Arch)

# Remove all cached package versions except the currently installed one
sudo paccache -r

# Remove ALL cached packages (more aggressive)
sudo pacman -Scc

paccache is part of the pacman-contrib package. Keeping one or two old versions in cache is useful if a package update breaks something, so paccache -r (keeps last 3) is a sensible default.

Remove Old Kernels

Every kernel update installs a new kernel and leaves the old one in place as a fallback. After a few updates you can accumulate 500 MB or more in /boot and /lib/modules. Keep at least one previous kernel before removing anything.

Debian / Ubuntu

# List installed kernels
dpkg --list | grep linux-image

# autoremove handles old kernels automatically on Ubuntu/Debian
sudo apt autoremove --purge

On Ubuntu, apt autoremove is usually enough — it marks kernels no longer needed as auto-removable after a new one is installed. Always confirm the list before accepting.

Fedora / RHEL / Rocky

# DNF keeps 3 kernels by default; reduce to 2
sudo dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)

# Or set the limit permanently in dnf.conf
echo 'installonly_limit=2' | sudo tee -a /etc/dnf/dnf.conf

Arch

Arch only installs a single kernel package at a time, so old kernels aren't normally left behind. If you use a custom or LTS kernel alongside the default, remove whichever you don't need with sudo pacman -R linux-lts (or the appropriate package name).

Trim systemd Journal Logs

By default, journald caps logs at 10% of the filesystem or 4 GB, whichever is smaller — but on systems that have been running a while, the journal can still consume over a gigabyte. Check and trim it:

# Check current journal disk usage
journalctl --disk-usage
# Delete logs older than 2 weeks
sudo journalctl --vacuum-time=2weeks

# Or cap the journal to 500 MB total
sudo journalctl --vacuum-size=500M

To make the size cap permanent, edit /etc/systemd/journald.conf:

sudo systemctl edit --force systemd-journald

Or directly set the option:

sudo sed -i 's/^#SystemMaxUse=.*/SystemMaxUse=500M/' /etc/systemd/journald.conf
sudo systemctl restart systemd-journald

Remove Orphaned Packages and Unused Dependencies

Debian / Ubuntu

sudo apt autoremove --purge

Fedora / RHEL / Rocky

sudo dnf autoremove

Arch

# List orphans (installed as deps but no longer needed)
sudo pacman -Qdtq

# Remove them all
sudo pacman -Rns $(pacman -Qdtq)

Be careful with the Arch command: review the list before confirming. Occasionally a package shows as orphaned but is something you actually want.

Clean Up /tmp and Application Caches

Temporary files

On systemd systems, /tmp is often a tmpfs (RAM-based) and cleared on reboot. /var/tmp persists across reboots and can accumulate data:

sudo du -sh /var/tmp
sudo rm -rf /var/tmp/*

User application caches

# See what your own home cache looks like
du -sh ~/.cache/*  | sort -rh | head -15

# Browsers, Electron apps, and Flatpaks are frequent offenders
du -sh ~/.var/app/*/cache/ 2>/dev/null | sort -rh

You can safely delete most contents of ~/.cache — applications rebuild their caches on next run. Do not blindly delete the entire directory; some apps store recoverable session data there.

Flatpak (if used)

# Remove unused Flatpak runtimes
flatpak uninstall --unused

Verify the Results

# Overall filesystem usage
df -h

# Check /boot specifically (important after removing kernels)
df -h /boot

A realistic cleanup on an older desktop or server typically recovers 2–10 GB. Output will vary by system, but you should see the Use% column drop noticeably on the relevant partition.

Troubleshooting

df shows disk nearly full but du totals don't add up

A running process can hold an open file descriptor to a deleted file, keeping the space allocated until the process closes or restarts. Find the culprit:

sudo lsof +L1 | grep deleted

Restart or kill the listed process (often a log daemon or database) to release the space immediately.

/boot is full but autoremove didn't help

On some Ubuntu systems with a separate small /boot partition, the autoremove logic occasionally misses old kernel packages. List and remove manually:

dpkg --list | grep -E 'linux-(image|headers|modules)' | awk '{print $2}'
# Then: sudo apt purge 

Never remove the kernel version currently running. Check the running kernel with uname -r first.

Snap packages (Ubuntu)

Snap keeps two old revisions of every installed snap. Disable this if space is tight:

# List old snap revisions
snap list --all | awk '/disabled/{print $1, $3}'

# Remove all disabled revisions (run a few times if needed)
snap list --all | awk '/disabled/{print $1, $3}' | while read name rev; do
  sudo snap remove "$name" --revision="$rev"
done
tested on:Ubuntu 24.04Debian 12Fedora 40Arch rolling

Frequently asked questions

Is it safe to run apt clean or dnf clean all?
Yes. Cleaning the package cache only removes downloaded archive files. Your installed software is unaffected; packages are simply re-downloaded from the internet if you need to reinstall or downgrade them later.
How do I know which kernel is currently running before I delete old ones?
Run 'uname -r' to print the exact version string of the running kernel. Never remove a package whose version matches that string.
df says my disk is full but I can't find the files with du — why?
A process likely holds an open file descriptor to a deleted file, keeping the blocks allocated. Use 'sudo lsof +L1 | grep deleted' to find the process, then restart it to release the space.
Will vacuuming the systemd journal delete logs I still need?
Vacuum commands only remove the oldest journal segments to meet your time or size target. If you need to retain logs for compliance or debugging, archive them first with 'journalctl --since ... > archive.log' before vacuuming.
How can I prevent the disk from filling up again automatically?
Set SystemMaxUse in /etc/systemd/journald.conf, configure installonly_limit in /etc/dnf/dnf.conf (Fedora/RHEL), and consider a weekly systemd timer or cron job running apt autoclean or paccache -r to keep caches in check.

Related guides