Remove Unsed Linux Kernels

I hate manually cleaning out all of the old kernels here is a script to do it for you:

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

This was stole directly from here.

For good measure I run the following after to be sure the grub config is good:

sudo update-grub2

Reboot to make sure everything is OK.

Which much restraint I avoided including several bad un-popped popcorn references.

This entry was posted in Linux General. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.