Skip to main content

Remove Old Linux Kernels on Ubuntu

Show all kernels

dpkg -l linux-image-\* | grep ^ii

Single command to SHOW all kernels and headers that can be removed, excluding the current running kernel

dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve $kernelver

Single command to REMOVE all kernels and headers that can be removed, excluding the current running kernel

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | grep -E "(image|headers)" | xargs sudo dpkg --remove