How To clean Linux Kernal Headers

Every time Ubuntu installs a new Linux kernel, the old one is left behind.
This means that if you are regularly updating an Ubuntu system the Grub boot
menu becomes longer and longer with kernels you don't need anymore. those
previous kernels, images and modules are usually just wasting space.

The old kernels are deliberately left installed and on the menu so you can
boot a previous kernel if you have trouble with a new one. But if the new
one works, you can safely uninstall the old kernel, which will also result
in the Grub menu being cleaned up.

To remove all the unused Linux Kernel headers, images and modules, simply
run this command:

 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
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: