Skip to content

Instantly share code, notes, and snippets.

@ccammilleri
Created November 3, 2016 00:57
Show Gist options
  • Save ccammilleri/06817f07577d1308c6964de68560bb47 to your computer and use it in GitHub Desktop.
Save ccammilleri/06817f07577d1308c6964de68560bb47 to your computer and use it in GitHub Desktop.
purge unused kernels in ubuntu to avoid boot partition form filling up
#! /bin/sh
dpkg --get-selections | grep 'linux-image-*' | awk '{print $1}' | egrep -v "linux-image-$(uname -r)|linux-image-generic" | head -n -2 | sed 's/^linux-image-\(.*\)$/\1/' | \
while read n; do
echo 'Purging unneeded kernel images and headers for: '$n
sudo apt-get --yes purge linux-image-$n #purge images
sudo apt-get --yes purge linux-headers-$n #purge headers
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment