Removes all but current kernel and headers. This is a note for personal use. Use at your own risk :)
dpkg-query -f '${Package}\n' -W | egrep 'linux-(headers|image)-[[:digit:]].*(|-generic)' | grep -v $(uname -r | sed 's/-generic//') | sudo xargs apt-get -q -q -yy --purge remove
Breakdown 🔗
- List all packages.
- Find only linux-image and linux-header packages with version number, not the two main meta packages.
- Remove the linux-image and linux-header for running kernel from the list.
- Purge all listed packages from system without asking any questions.