Just a short post about some useful cleanup commands for Debian and Ubuntu systems. There are (to my knowledge) no build in task solving the following things
- Remove old kernels (while keeping the currently running and the latest)
- Purge removed packages (especially after autoremoving unneeded dependencies)
If this post was helpful to you, please consider supporting me.
# Remove old kernels
Debian and Ubuntu don’t remove old kernels when upgrading. Although this of course makes sense to keep the system bootable in case of a broken kernel, it can fill up /boot pretty quickly. Usually it should be sufficient to keep the currently running kernel, as well as the latest one. The rest can be safely deleted. This can be done with the following command:
A short explanation
1 2 3 4 5 6 7 8
# Purge removed packages
If you remove a package using
The packages configuration will be retained. Also, when autoremoving unneeded dependencies, apt-get by default removes packages instead of purging them.
To cleanup your system and purge all packages that are removed from the system and their dependencies, use this command
1 2 3 4 5
# apt cookbook
Furthermore, I created the apt_cleanup Chef cookbook, which provides recipes to do all those tasks automatically.
For a convenient auto-cleanup, the following recipes can be used
Includes all other cleanup recipes
Removes all old kernels, but the most recent as well as the currenlty used one.
apt-get autoremove to remove packages not required anymore.
Purges already removed packages, to get rid of e.g. old config files.
apt-get clean to remove
.dpkg files from