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 free up disk space on Linux the right way, systematically working through each of the usual culprits.
Updated October 2026: added a fast-wins list, a section on why df and du disagree, and a safety checklist.
Free Up Disk Space on Linux: The Fast Wins
If you just need space back quickly, work through these in order. They are the safest and usually recover the most:
- Find the biggest folders:
sudo du -xh / --max-depth=1 2>/dev/null | sort -rh | head - Clear the package cache:
sudo apt clean && sudo apt autoremove(Debian and Ubuntu),sudo dnf clean all(Fedora) orsudo pacman -Sc(Arch) - Trim the systemd journal:
sudo journalctl --vacuum-size=500M - Prune Docker if you use it:
docker system prune - Remove unused Flatpak runtimes:
flatpak uninstall --unused
The sections below explain each step, what is safe to delete, and how to find the cause when none of these help.
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 orrm -rf ~/.local/share/Trash/*~/.npmand~/.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.
When df and du Disagree
If df -h says the disk is full but du only accounts for part of it, the space is usually held by files that have been deleted while a program still has them open. Typical culprits are a log file deleted without restarting the service that writes it. List them with:
sudo lsof +L1
Restarting the program that holds the file (for example sudo systemctl restart service-name) releases the space. This is also why a reboot can suddenly free gigabytes.
No Space Left on Device, But df Shows Free Space
The filesystem can also run out of inodes, the records that track each file, even when there are free blocks. Check with:
df -i
If IUse% is at 100%, a directory somewhere contains a huge number of tiny files, such as mail queues, session files or build caches. Find the folder with sudo find / -xdev -type d -size +1M 2>/dev/null and clear out what you no longer need.
Keep Fewer Snap Revisions
Snap keeps old revisions of every package. You can reduce how many are kept so the problem does not come back:
sudo snap set system refresh.retain=2
Safety Checklist Before You Delete Anything
- Check what a command will remove before you run it.
apt autoremove --dry-runanddocker system dfboth show what is at stake. - Never delete files from
/usr,/libor/bootby hand. Use the package manager. - Keep the running kernel (
uname -r) and at least one older one. - Be careful with
rm -rfand wildcards. Double-check the path, especially when usingsudo. - Back up anything irreplaceable before a big cleanup. A cleared Docker volume or
~/.cacheentry can’t be restored.
To dig into a specific folder, see how to find the ten biggest files or directories in Linux.
