This just prompted me to tidy up a couple of machines, here's what I came up with:
Code:
dpkg -l | grep 'ii linux-image\|ii linux-headers\|ii linux-modules\|ii linux-tools' | cut -d ' ' -f3 | grep -v `uname -r | cut -d '-' -f1-2` | grep '[0-9]' > oldKernels && sudo apt remove `cat oldKernels`
List available packages (dpkg -l)
Filter down to the target packages, that are also installed (grep 'ii linux-image\|ii linux-headers\|ii linux-modules\|ii linux-tools')
Chop the line up and just get the package name (cut -d ' ' -f3)
Filter out the packages for the currently running kernel (grep -v `uname -r | cut -d '-' -f1-2`)
Filter down to packages containing numbers to exclude linux-image-generic etc (grep '[0-9]')
Finally redirect the list of packages to a file and uninstall them.
This worked for me, but
check the list of packages carefully before pressing y!