📝 Introduction
Over time, Ubuntu stores temporary files such as caches, thumbnails, and installer leftovers. Removing these can free disk space and sometimes speed up your system. This guide shows two safe ways to clean temporary files in Ubuntu 24.04.3 LTS: a simple graphical method and terminal commands you can copy and paste.
📦 What are temporary files?
- /tmp: short-lived files used by applications and the system.
- APT cache: downloaded package files (
.deb) kept after installation. - User cache: files in
~/.cache(per-app caches that can be rebuilt). - Thumbnail cache: image previews stored in
~/.cache/thumbnails. - Snap cache (optional): temporary Snap downloads in
/var/lib/snapd/cache.
Important: Deleting caches is usually safe. Applications may rebuild them, which can temporarily use CPU/disk the next time you open the app.
🖱️ Method 1: Use the Graphical Interface (beginner)
- Open Files (also called Nautilus).
- Click ☰ (menu) → Preferences → Search & Preview and ensure previews are reasonable (optional).
- Clear Trash:
- In the sidebar, click Trash.
- Click Empty to remove deleted files permanently.
- Clear Downloads (optional):
- Open Downloads and remove files you no longer need.
- Clear Thumbnail Cache:
- Press Ctrl + L, paste:
~/.cache/thumbnails, then press Enter. - Select everything and delete it. Thumbnails will be recreated when needed.
- Press Ctrl + L, paste:
- Review Disk Usage Analyzer:
- Open Software → search for Disk Usage Analyzer (also known as Baobab) and open it.
- Scan your home folder or entire filesystem to find large folders to clean (avoid system files unless sure).
Tip: Rebooting Ubuntu often clears many temporary files in /tmp automatically.
🧰 Method 2: Use the Terminal (copy & paste)
Below are safe, targeted commands. Read the explanation before running each command.
1) See what’s taking space (diagnose first)
What it does: Shows disk usage for common temporary locations so you know where cleanup will help most.
sudo du -h --max-depth=1 /tmp /var/cache/apt /var/lib/snapd/cache ~/.cache 2>/dev/null | sort -h
2) Clean system temporary files via systemd-tmpfiles
What it does: Asks systemd to clean temporary files according to Ubuntu’s safety rules (age/paths).
sudo systemd-tmpfiles --clean
3) (Optional) Manually clear /tmp
What it does: Removes everything under /tmp. Only use if you need immediate cleanup and no apps are using files there.
Note: Close open applications first. If unsure, prefer the previous command.
sudo rm -rf /tmp/*
4) Clean APT package cache
What it does: Removes downloaded .deb packages you no longer need.
sudo apt clean
Alternative: Remove only outdated package files (keeps current ones):
sudo apt autoclean
5) Clear your user cache
What it does: Deletes cached data in your home directory that apps can recreate.
Important: This is usually safe, but apps may re-cache and use CPU/disk briefly next launch.
rm -rf ~/.cache/*
6) Clear thumbnail cache (fast and safe)
What it does: Removes image/video thumbnails; they regenerate as needed.
rm -rf ~/.cache/thumbnails/*
7) (Optional) Clear Snap download cache
What it does: Deletes temporary Snap downloads. Safe to remove.
sudo rm -rf /var/lib/snapd/cache/*
8) (Optional) Limit system journal size
What it does: Trims old logs to keep only the last 7 days (logs are not “temp files” but can be large).
sudo journalctl --vacuum-time=7d
9) Verify freed space
What it does: Shows disk usage before/after to confirm cleanup.
df -h
📋 Common cleanup tasks (copy & paste)
Quick clean (safe defaults)
What it does: Cleans system temp via systemd, APT cache, and thumbnails—good first pass.
sudo systemd-tmpfiles --clean && sudo apt clean && rm -rf ~/.cache/thumbnails/*
Deep user cache clean
What it does: Clears your entire user cache. Apps may rebuild cache on next start.
rm -rf ~/.cache/*
Everything common (use with care)
What it does: Runs most of this guide in one line. Read it before running.
sudo systemd-tmpfiles --clean \
&& sudo apt clean \
&& rm -rf ~/.cache/thumbnails/* \
&& rm -rf ~/.cache/*
💡 Tips & Safety Notes
- Close apps first to avoid deleting files in use.
- Prefer systemd-tmpfiles for safe, policy-based cleaning.
- Reboot if something can’t be deleted; it often unlocks
/tmpfiles. - Back up important data regularly—cleanup should not touch documents, but backups are always smart.
- Use sudo carefully and copy commands exactly as shown.
🛠 Troubleshooting
“Permission denied” while cleaning?
→ Add sudo for system folders like /tmp or /var/*.
“Device or resource busy” for /tmp files?
→ An app is using the file. Close apps or reboot, then try again.
System feels slow after clearing caches?
→ Normal. Apps rebuild caches on first run. Performance returns to normal shortly.
Low space persists?
→ Use Disk Usage Analyzer to find large folders outside “temp” (e.g., videos, VMs, containers).
📚 Resources & Further Reading
- Ubuntu Documentation – https://help.ubuntu.com/
- man pages –
man systemd-tmpfiles,man apt,man journalctl - GNOME Help (Files/Nautilus) – Nautilus user guide
Note: Commands are written for Ubuntu 24.04.3 LTS (Noble). They also work for most modern Ubuntu versions.