Linux Clean Up Free Storage Routine
In this article
To clean up free storage on Linux, you need to remove package caches, orphaned dependencies, old logs, and temporary files, then check for large files you no longer need. A solid routine combines a few built-in commands with a periodic review of your disk usage. This article walks through the most effective methods, explains what each command does, and helps you build a maintenance schedule that keeps your system lean without risking important data.
Why Linux Storage Gets Cluttered
Linux systems accumulate junk over time through normal use. The most common culprits are:
- Package manager caches – downloaded .deb, .rpm, or other package files stay in /var/cache after installation.
- Orphaned dependencies – packages installed automatically as dependencies often remain after the parent package is removed.
- Old kernels – every kernel update adds a new entry, and old ones are rarely removed automatically.
- Log files – system logs in /var/log can grow large, especially if log rotation is misconfigured.
- Thumbnail caches and user caches – desktop environments generate thumbnails and other cache files in your home directory.
- Trash and temporary files – files you delete to the trash still occupy space until emptied; /tmp can also fill up.
Understanding these sources helps you target the biggest offenders first.
Check Disk Usage First
Before deleting anything, see where space is going. The df command shows overall filesystem usage:
df -hThis lists mounted filesystems with human-readable sizes. Look for the partition that is full (often / or /home).
For a detailed view of which directories are largest, use du:
du -h --max-depth=1 / 2>/dev/null | sort -hr | head -20This scans the root directory, shows the top 20 subdirectories by size, and suppresses permission errors. You can run it on /home or /var to drill down further.
A graphical alternative is ncdu, which provides an interactive, navigable interface. Install it with your package manager (e.g., sudo apt install ncdu on Debian/Ubuntu) and run ncdu / to browse sizes.
Clean Package Manager Caches
Package managers store downloaded packages so they can be reinstalled without re-downloading. Over time, these caches can consume gigabytes.
- Debian/Ubuntu (apt):
sudo apt cleanremoves all .deb files from /var/cache/apt/archives.sudo apt autoremoveremoves orphaned dependencies.sudo apt autocleanremoves only outdated package files. - Fedora/RHEL (dnf):
sudo dnf clean allclears the cache.sudo dnf autoremoveremoves unused dependencies. - Arch (pacman):
sudo pacman -Scremoves old package versions from the cache (keeps the latest).sudo pacman -Sccremoves everything in the cache.sudo pacman -Qdtq | sudo pacman -Rs -removes orphaned packages (be careful – review the list first). - openSUSE (zypper):
sudo zypper cleanclears the cache.sudo zypper packages --orphanedlists orphans; you can remove them withsudo zypper rm.
Run autoremove after uninstalling software to catch leftover dependencies.
Remove Old Kernels
Kernels are large (hundreds of MB each) and old ones are rarely needed. Most distributions keep the latest kernel and one or two previous ones for fallback. Removing older kernels is safe if you keep at least one known-good backup.
- Debian/Ubuntu:
sudo apt autoremove --purgewill remove old kernels that are no longer needed. You can also list installed kernels withdpkg --list | grep linux-imageand manually remove specific ones withsudo apt purge linux-image-<version>. - Fedora:
sudo dnf remove --oldinstallonlyremoves old kernels, keeping the default number (usually 3). - Arch:
sudo pacman -Qdtq | grep linuxto find orphaned kernels, then remove them individually. Or usepaccache -rk1to keep only the latest kernel in the cache.
Always reboot after removing a kernel to ensure the system still boots correctly.
Clear Logs and Temporary Files
System logs can grow large, especially if a service is misbehaving. The journald service (used by systemd) stores logs in /var/log/journal. To see how much space it uses:
journalctl --disk-usageTo vacuum logs older than 7 days:
sudo journalctl --vacuum-time=7dYou can also set a size limit in /etc/systemd/journald.conf by uncommenting SystemMaxUse=100M and restarting journald with sudo systemctl restart systemd-journald.
For /tmp, files are usually cleared on reboot, but you can manually remove contents with sudo rm -rf /tmp/* (make sure no critical processes are using it).
To find large log files, use sudo find /var/log -type f -size +100M and review them. Rotate logs with logrotate if needed – most distributions already have this configured.
Clean User Caches and Trash
Your home directory often holds hidden caches that eat space. Common ones include:
- Thumbnails: ~/.cache/thumbnails – delete with
rm -rf ~/.cache/thumbnails/*; they regenerate as needed. - Browser caches: Firefox, Chrome, and others store cache in ~/.cache/mozilla or ~/.cache/google-chrome. Clearing them via the browser’s settings is safer.
- Package manager caches in user space: pip, npm, and other language package managers store caches in ~/.cache/pip, ~/.npm, etc. Use their built-in cleanup commands (e.g.,
pip cache purge,npm cache clean --force). - Trash: Empty it with
rm -rf ~/.local/share/Trash/*(or use your file manager).
You can use the du command on ~/.cache to see which cache is largest and target it.
Find and Remove Large Unused Files
Sometimes the biggest space hogs are files you forgot about – old ISOs, backups, videos, or downloads. Use find to locate files larger than a certain size:
find /home -type f -size +500M -exec ls -lh {}
t;This lists all files over 500MB in /home. Review the list and delete or move anything you don’t need.
Another useful tool is du on specific directories like /var and /opt, which often hold large application files.
For a more visual approach, install a disk usage analyzer like baobab (GNOME) or qdirstat to see a graphical breakdown.
Automate the Routine with a Script
Once you know which commands work for your distribution, you can combine them into a script and run it periodically. A basic example for Debian/Ubuntu:
#!/bin/bash
sudo apt update
sudo apt autoremove --purge -y
sudo apt clean
sudo journalctl --vacuum-time=7d
rm -rf ~/.cache/thumbnails/*
Save it as cleanup.sh, make it executable with chmod +x cleanup.sh, and run it with sudo ./cleanup.sh. You can schedule it with cron or a systemd timer, but be cautious – some operations require manual review (like removing orphans).
For a more comprehensive tool, consider bleachbit, which provides a GUI and CLI for cleaning common caches and temporary files. It’s available in most repositories, but review its options carefully to avoid deleting something you need.
Frequently Asked Questions
Is it safe to delete /var/cache/apt/archives?
Yes, those are just downloaded package files. Deleting them only means that if you need to reinstall a package, it will be downloaded again. apt clean does exactly this and is safe.
How do I know which old kernels I can remove?
Keep the kernel you are currently running (check with uname -r) and at least one previous version. On Debian/Ubuntu, apt autoremove --purge automatically keeps the latest kernel and removes older ones that are no longer needed.
Why does my disk still show full after deleting files?
Deleted files may still be held open by a process. Use lsof +L1 to find deleted files that are still in use, then restart the offending process. Also check for hidden files in your home directory with du -sh ~/.*.
Can I use bleachbit to clean everything?
Bleachbit can clean many caches and temporary files, but it’s best to review its list before running. Some options (like free disk space) can take a long time and may not be necessary. Avoid using it as root unless you know what you’re doing.
How often should I run a cleanup?
For most users, a monthly routine is enough. If you install and remove a lot of software, or your disk is small, run it weekly. The key is to check disk usage regularly and act when the free space drops below 10-15%.
What is the difference between apt clean and apt autoclean?
apt clean removes all package files from the cache. apt autoclean only removes package files that are no longer available in the repositories – it’s more conservative and keeps recent downloads.