#!/bin/bash # This will purge the kernels we are not using from the system. # You might want to run apt-get once without the "-y" just to make sure you're # not going to hose yourself. # Mario Stargard, Sep 12 2011 # Mario Stargard, Nov 10 2011 # Actually works now. DASHY="-y" # Our running kernel version # We don't want the full release, just the version number since the release # will have dependancies on other stuff with the version number. version=$( uname -r |awk -F- '{ printf("%s-%s\n", $1, $2 )}' ) # Exlude our currently running kernel version # and remove the remaining linux-image and linux-headers. dpkg --get-selections "linux-image-[0-9]*" "linux-headers-[0-9]*" | awk '{ print $1 }' |egrep -v "${version}\$|${version}-"| xargs apt-get $DASHY remove --purge