Windows cleanmgr (Disk Cleanup) equivalent in Linux
Removes temporary files, old package caches, and other items that can safely be deleted to recover disk space.
cleanmgr (Disk Cleanup)
sudo apt clean && sudo apt autoremove
sudo dnf clean all && sudo dnf autoremove
sudo pacman -Sc
Overview
What this command does
Removes temporary files, old package caches, and other items that can safely be deleted to recover disk space.
ncdu is useful for finding large directories before deleting anything. Install it with your distribution package manager, then run sudo ncdu /.Practical tasks
Common use cases
Free up disk space
Removes temporary files, old package caches, and other items that can safely be deleted to recover disk space.
sudo apt clean && sudo apt autoremove
Debian/Ubuntu: clear downloaded packages and remove unused dependencies
sudo dnf clean all && sudo dnf autoremove
Fedora: clear cached metadata/packages and remove unused dependencies
sudo pacman -Sc
Arch: remove packages that are no longer installed from the package cache
Ready to run
Copyable Linux commands
Review paths, device names, package names and permissions before running any command.
sudo apt clean
sudo apt autoremove
sudo dnf clean all
sudo dnf autoremove
sudo pacman -Sc
sudo journalctl --vacuum-size=200M
Walkthrough
Examples with explanations
# Debian/Ubuntu package cache and unused dependencies:
sudo apt clean
sudo apt autoremove
# Fedora package cache and unused dependencies:
sudo dnf clean all
sudo dnf autoremove
# Arch package cache (review the prompt before confirming):
sudo pacman -Sc
# Any systemd-based distribution: limit journal size:
sudo journalctl --vacuum-size=200M
Reference
Common options and variations
| Command or option | Use |
|---|---|
sudo apt clean && sudo apt autoremove | Debian/Ubuntu: clear downloaded packages and remove unused dependencies |
sudo dnf clean all && sudo dnf autoremove | Fedora: clear cached metadata/packages and remove unused dependencies |
sudo pacman -Sc | Arch: remove packages that are no longer installed from the package cache |
sudo journalctl --vacuum-size=200M | All three distributions: trim the systemd journal to approximately 200 MB |
sudo ncdu / | Interactively inspect disk usage before cleaning |
Distro differences
Debian/Ubuntu vs Fedora vs Arch
Package-cache cleanup is distribution-specific, while systemd journal cleanup uses journalctl on Debian/Ubuntu, Fedora and Arch.
| Distribution | Package manager / base | Equivalent command | Difference to notice |
|---|---|---|---|
| Debian/Ubuntu | apt | sudo apt clean && sudo apt autoremove |
APT separates cache cleanup from removal of unused dependency packages. |
| Fedora | dnf | sudo dnf clean all && sudo dnf autoremove |
DNF can clear cached metadata/packages and remove dependencies no longer required. |
| Arch | pacman | sudo pacman -Sc |
Removes cached packages that are no longer installed; review the confirmation prompt. |
Important
What to watch out for
Keep learning