- #!/bin/sh
- if [ $UID -ne 0 ]; then
- echo "This script must be ran as root."
- exit 1
- fi
- IGNORE_LIST="linux-image-generic"
- KERNEL_LIST=$(dpkg --get-selections | grep ^linux-image- | cut -f1 | grep -Ev "^($IGNORE_LIST)" | cut -d- -f3-)
- # Needed in case latest kernel isn't the currently running one.
- LATEST_KERNEL=$(echo "$KERNEL_LIST" | sort -V | tail -n1)
- OLD_KERNELS=$(echo "$KERNEL_LIST" | grep -Ev "^($LATEST_KERNEL|$(uname -r))")
- if [ -n "$OLD_KERNELS" ]; then
- UNINSTALL=
- for k in $OLD_KERNELS; do UNINSTALL="$UNINSTALL linux-image-$k linux-headers-$k"; done
- dpkg -P $UNINSTALL
- fi
bash script to uninstall old kernels (dpkg)
Posted by Admin on Wed 20th Jul 2011 11:45
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.