Created
July 8, 2015 20:47
-
-
Save gorango/90c789a504f3011da832 to your computer and use it in GitHub Desktop.
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 | |
# Ubuntu kernel cleanup: | |
# Save the 2 latest kernels and remove the old | |
IMAGES=($(dpkg --get-selections | grep "linux-image-[[:digit:]].*" | tr "\t" ";" | cut -d ";" -f1)) | |
HEADERS=($(dpkg --get-selections | grep "linux-headers-[[:digit:]].*" | tr "\t" ";" | cut -d ";" -f1)) | |
I_LEN=${#IMAGES[@]} | |
H_LEN=${#HEADERS[@]} | |
if [ $I_LEN>2 ] ; then | |
for (( i=0; i<(${I_LEN}-2); i++ )) ; do | |
sudo apt-get purge ${IMAGES[$i]} | |
done | |
sudo apt-get autoclean && sudo apt-get autoremove | |
fi | |
if [ $H_LEN>2 ] ; then | |
for (( i=0; i<(${H_LEN}-2); i++ )) ; do | |
sudo apt-get purge ${HEADERS[$i]} | |
done | |
sudo apt-get autoclean && sudo apt-get autoremove | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment