Linux Disk Space Full How to Clean Up
A full disk can grind a Linux system to a halt, breaking services and blocking logins. The fix is methodical: find what’s consuming space, then clean it safely. This guide shows you exactly how to reclaim disk space on any Linux machine.
Step 1: Check How Full Your Disk Is
Start with a clear picture of usage. The df command reports free space per filesystem:
Read also: Linux File Permissions Explained Comprehensive Guide
df -h
The -h flag shows human-readable sizes. Look at the Use% column for the filesystem mounted on /. If it’s at 100%, that’s your problem. If / has space but you still get “no space left,” you may have run out of inodes instead — check with df -i.
Step 2: Find What’s Eating the Space
The du command measures directory sizes. Find the biggest offenders from the root:
sudo du -h --max-depth=1 / | sort -rh | head -20
This lists the top directories by size. Drill into whichever is largest, for example sudo du -h --max-depth=1 /var | sort -rh | head. For an interactive, visual explorer, install and run ncdu:
sudo ncdu /— navigate the tree and delete files in place.
The usual culprits are logs in /var/log, package caches, old kernels, Docker images, and forgotten files in your home directory.
Step 3: Clean the Package Cache
Package managers keep downloaded archives that can grow large. Clear them based on your distro:
- Debian/Ubuntu:
sudo apt cleanremoves cached.debfiles, andsudo apt autoremove --purgedeletes unused dependencies and old kernels. - Fedora/RHEL:
sudo dnf clean allandsudo dnf autoremove. - Arch:
sudo pacman -Sctrims the cache;paccache -rkeeps only recent versions.
Step 4: Truncate Logs and Clear the Journal
System logs are a top consumer on long-running servers. The systemd journal can be vacuumed safely:
journalctl --disk-usage— see how much the journal occupies.sudo journalctl --vacuum-time=7d— keep only the last 7 days.sudo journalctl --vacuum-size=200M— or cap it at a fixed size.
For other logs in /var/log, compress or rotate them with logrotate rather than deleting active files. To empty a growing log without breaking the writing process, use sudo truncate -s 0 /var/log/large.log.
Step 5: Remove Other Common Space Hogs
- Docker:
docker system prune -aremoves unused images, containers, and networks. This often frees gigabytes. - Thumbnails and trash: clear
~/.cache/thumbnailsand empty~/.local/share/Trash. - Old snapshots/backups: check tools like
timeshiftorsnapperfor accumulated snapshots. - Orphaned large files: find files over 500 MB with
sudo find / -type f -size +500M -exec ls -lh {} \;.
After cleanup, run df -h again to confirm the space was reclaimed. If a deleted file’s space doesn’t return, a process may still hold it open — restart that service or use lsof | grep deleted to find it.
Frequently Asked Questions
What’s the difference between df and du?
df reports free and used space per filesystem, giving the big picture. du measures the size of specific directories so you can pinpoint what’s actually consuming the space.
I deleted files but free space didn’t increase. Why?
A running process is probably still holding the deleted file open, so the kernel won’t release the space until it closes. Find it with lsof | grep deleted and restart that process.
Is it safe to clear the systemd journal?
Yes. journalctl --vacuum-time=7d only removes old log entries and never affects running services. It’s a standard, safe way to reclaim space on servers.
What does “no space left” mean if df shows free space?
You’ve likely exhausted inodes rather than bytes, common when a directory holds millions of tiny files. Confirm with df -i and delete the excess small files to recover.






