Remove all unused kernels with apt-get

sudo apt-get remove $(dpkg -l|awk '/^ii linux-image-/{print $2}'|sed 's/linux-image-//'|awk -v v=`uname -r` 'v>$0'|sed 's/-generic*//'|awk '{printf("linux-headers-%s\nlinux-headers-%s-generic*\nlinux-image-%s-generic*\n",$0,$0,$0)}')
Remove old kernels (*-generic and *-generic-pae) via apt-get on debian/ubuntu based systems. Tested on ubuntu 10.04 - 12.04.

By: mtron
2012-08-15 10:02:12

11 Alternatives + Submit Alt

What Others Think

I'd add the --purge option after remove so there's nothing left behind.
unixmonkey10245 · 521 weeks and 6 days ago
Here they have shared the code for removing all unused kernels with apt-get and they have given a detailed explanation here which is definitely a useful One For The programmers as they have explained everything clearly in this post">certified loose diamonds wholesale
Kaitlyn · 16 weeks and 6 days ago
You can learn so many such Unix commands through this website and good to see the details mentioned here. The above cbd pet medicines command is used to remove all unused kernels with apt-get. You can learn so many such commands from here and I am looking here for more updates on that.
Alyssalauren · 12 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: