Last active
May 9, 2016 07:13
-
-
Save bse666/63fa045866fa12ab9fb5cc6ab24f7deb to your computer and use it in GitHub Desktop.
Purge old kernel's on reboot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
dpkg --get-selections | `#show all installed packages` \ | |
grep 'linux-image-*' | `#select all installed images` \ | |
awk '{print $1}' | `#select only package name)` \ | |
egrep -v "linux-image-$(uname -r)|linux-image-generic" | `#remove current and base kernel from list` \ | |
head -n -2 | `#remove two recent kernels from list` \ | |
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
crontab: @reboot purge-old-kernels.sh