26
Aug
2011
david

Bash One-liner to Remove Old Kernels

I had 800MB of space taken up by old kernels, header files, and kernel modules. On most modern systems, this is no big deal. On my netbook, with it’s 30GB ssd, every gig is precious.

 

I found this bash one-liner on commandlinefu.com that works for Ubuntu and should work for any other Debian-based distro. Worked like a charm. It took a little while to run, since after removing each kernel and it’s dependent files it regenerated the grub boot files.

 

For the lazy:

sudo apt-get -y purge $(dpkg --get-selections | awk '((/^linux-/) && (/[0-9]\./) && (!/'"`uname -r | sed "s/-generic//g"`"'/)) {print $1}')