delete-all-old-kernels-easily.sh 674 B

123456789101112131415
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # # Get kernel version #
  4. # v="$(uname -r | awk -F '-virtual' '{ print $1}')"
  5. # # Create ignore list to avoid deleting the running kernel #
  6. # i="linux-headers-virtual|linux-image-virtual|linux-headers-${v}|linux-image-$(uname -r)"
  7. # # Display the list #
  8. # echo dpkg --list | egrep -i 'linux-image|linux-headers' | awk '/ii/{ print $2}' | egrep -v "$i"
  9. v="$(uname -r | awk -F '-virtual' '{ print $1}')"
  10. i="linux-headers-virtual|linux-image-virtual|linux-headers-${v}|linux-image-$(uname -r)"
  11. sudo apt-get --purge remove $(dpkg --list | egrep -i 'linux-image|linux-headers' | awk '/ii/{ print $2}' | egrep -v "$i")