Last active
January 7, 2016 13:25
-
-
Save bse666/b46a089b73c17facb2d2 to your computer and use it in GitHub Desktop.
Purge unused Kernels on Ubuntu
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 [0/1863] | |
# /root/ubuntu-purge-unused-kernels.sh | |
# crontab: | |
# @reboot /root/ubuntu-purge-unused-kernels.sh | |
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