Script for Removing Old Kernels and Linux Headers

This oneliner removes all the unused kernels and headers, on Ubuntu, Linux Mint, Knoppix or Debian Systems.

$ 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

If you want to get free space and regularry delete the kernels and headers that you don’t need, run this oneliner monthly with cron.

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Support LinuxG via Patreon
Support LinuxG.net on Patreon!
Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!