Originally Posted By: Garak
Originally Posted By: uc50ic4more
$ dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
I thought I spend a lot of time in the command line, but that's inscrutable.
I just thought this morning about how easy it'd be to create a bash alias for this monster; so I did:
In your ~/.bash_aliases file (which you may well have to create) use this:
Code:
alias kernelpurge="dpkg -l linux-{image,headers}-* | awk '/^ii/{print $2}' | egrep '[0-9]+\.[0-9]+\.[0-9]+' | grep -v $(uname -r) | xargs sudo apt-get -y purge"
... Then you need only type kernelpurge in your terminal.
I haven't tested the following out yet; but you might, if you're not a GUI guy who just likes to go along with the prompts from your Update Manager, create a cron job calling a (executable) script of your naming, containing this:
Code:
sudo apt-get update && sudo apt-get upgrade && sudo apt-get autoremove && kernelpurge