A cluttered computer desk used to illustrate Linux cleanup habits

Linux Cleanup Habits That Free Space Safely

Spread the love

Measure first: df and du show where the space went

Before you delete anything, find out which folder is the problem. Open a terminal and run df -h. It lists each mounted filesystem with its size and how full it is. Look at the line for / and, if you have one, /home. A small root partition can fill up while your home partition sits half empty, and the fix for each is different.

Next, drill down with du. From your home folder, run du -h --max-depth=1 ~ | sort -h. The biggest folders land at the bottom of the list. Repeat inside the largest one until you reach the real culprit. For the system side, use sudo du -xh --max-depth=1 / | sort -h. The -x flag keeps du on one filesystem, so it does not wander into mounted drives or network shares and give you a confusing total.

For something visual, install ncdu, or use GNOME’s Disk Usage Analyzer (Baobab) or KDE’s Filelight. Expect an unglamorous answer. Video files, VM images, and game libraries often beat any system cache, and moving those to an external drive is cleaner than any command here.

Package caches and old kernels

Your package manager keeps downloaded installers so it can reinstall quickly. That is convenient, but the cache grows forever unless you trim it. The commands differ by distribution:

  • Debian, Ubuntu, Mint: sudo apt clean empties the download cache, and sudo apt autoremove removes dependencies nothing needs anymore.
  • Fedora: sudo dnf clean all drops cached metadata and packages, and sudo dnf autoremove handles orphaned dependencies.
  • Arch and Manjaro: paccache -r from the pacman-contrib package keeps the last three versions of each package. Running pacman -Scc wipes everything, which removes your ability to roll back a bad update, so use it sparingly.

Read the list autoremove shows you before typing yes. If a package you rely on appears there, it was probably installed as a dependency of something you removed earlier. Mark it as manually installed first, then continue.

Old kernels are the other slow leak, especially on Ubuntu-family systems, where each update can leave a previous kernel behind. Check what you are running with uname -r. Then keep the running kernel plus at least one older one as a fallback. If the newest kernel fails to boot on your hardware, that spare gets you back to a working desktop from the boot menu. Let autoremove prune the rest rather than deleting files from /boot by hand.

Terminal showing disk usage output while cleaning a Linux laptop

Journal logs, /tmp, and thumbnail caches

On systems that use systemd, logs live in the journal. Check its size with journalctl --disk-usage. If it has crept into the gigabytes, trim it with sudo journalctl --vacuum-size=200M or by age with sudo journalctl --vacuum-time=2weeks. To stop it growing back, edit /etc/systemd/journald.conf, set SystemMaxUse=200M under the [Journal] section, and restart the service with sudo systemctl restart systemd-journald. The trade-off is real: a smaller journal means less history when you are chasing a crash from three weeks ago.

The /tmp folder is designed to be disposable, and many distributions clear it at every reboot. A restart is the safest cleanup. Do not delete files from it while programs are running, because applications keep sockets and lock files there.

Thumbnails sit in ~/.cache/thumbnails. They are previews your file manager regenerates on demand, so deleting them is harmless. The only cost is a short delay the next time you open a folder full of photos. Browser caches are better cleared from the browser’s own privacy settings than by removing profile folders.

Flatpak and Snap leftovers

Sandboxed apps carry their own copies of libraries, and old ones linger after updates. For Flatpak, run flatpak uninstall --unused to remove runtimes that no installed app needs. Run flatpak list to see what you have, and remove apps you stopped using. Their data lives in ~/.var/app, and Flatpak does not always remove it on uninstall, so check that folder for stragglers.

Snap keeps older revisions of each package so it can roll back. List them with snap list --all and look for entries marked disabled. Remove one with sudo snap remove NAME --revision=NUMBER. To limit how many revisions Snap holds, run sudo snap set system refresh.retain=2. Two is the lowest value it accepts.

For more command patterns, see our guide to Linux disk cleanup commands for safer space recovery.

The difference between cleaning and breaking

A useful rule: clean things that something else can recreate, and leave alone things that only exist once. Caches, thumbnails, old logs, and downloaded installers are recreated when needed. Your documents, your configuration in ~/.config, and files in /etc, /usr, and /var/lib are not caches, even though they sit among folders that look like clutter.

Several habits keep you on the right side of that line:

  • Use the package manager’s own cleanup commands instead of rm on system paths.
  • Never paste a command with rm -rf and a wildcard from a forum without checking the path. A stray space can change what gets deleted.
  • Back up your home folder before a big cleanup, and test that you can open a file from the backup.

The Arch Wiki’s system maintenance guide explains these ideas in more depth, and most of it applies beyond Arch. For the hardware side, see simple laptop care habits that prevent repairs.

Scroll to Top