Last active
December 16, 2015 11:48
-
-
Save generalov/5429432 to your computer and use it in GitHub Desktop.
Purge old Ubuntu kernels
This file contains 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/dash | |
SUFFIX=$(uname -r | sed "s/^\(.*\)-\([^0-9]\+\)$/\2/") | |
GENERIC_VERSION=$(dpkg -l linux-$SUFFIX | awk '/^ii/{print $3}' | sed 's#^\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)\..*$#\1.\2.\3-\4#g' ) | |
CURRENT_VERSION=$(uname -r | sed "s/^\(.*\)-\([^0-9]\+\)$/\1/") | |
dpkg -l 'linux-image-*' 'linux-headers-*' \ | |
| grep -v 'linux-image-'$SUFFIX | grep -v 'linux-headers-'$SUFFIX \ | |
| grep -v $GENERIC_VERSION | grep -v $CURRENT_VERSION \ | |
| awk '/^ii/{print $2}' \ | |
| xargs sudo apt-get -y purge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment