Cookie Consent by Free Privacy Policy Generator Remove old kernels in Ubuntu | Igor Moiseev

Igor Moiseev Applied mathematician, Web Developer

Remove old kernels in Ubuntuedit

To remove old linux kernels and leave the current one

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

Be aware, the command uses uname -r to get the current kernel.

moiseevigor.github.io is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means to earn fees when linking to Amazon.com and affiliated sites.