Skip to content

Instantly share code, notes, and snippets.

@Programie
Created June 1, 2017 09:28
Show Gist options
  • Select an option

  • Save Programie/c33244f689b4d3464f96acb4230140d2 to your computer and use it in GitHub Desktop.

Select an option

Save Programie/c33244f689b4d3464f96acb4230140d2 to your computer and use it in GitHub Desktop.
Remove old and unused Linux Kernels on Debian
#! /bin/bash
dpkg --list | awk '{print $2}' | grep linux-image | grep -v -e linux-image-amd64 -e "linux-image-`uname -r`" -e `aptitude show linux-image-amd64 | grep '^Depends:' | cut -d : -f 2 | tr -d ' '` | xargs apt-get -y purge
@Programie
Copy link
Author

This will remove all installed Linux Kernels excluding the kernel currently in use (linux-image-uname -r) and excluding the latest kernel (found using "Depends" field of linux-image-amd64 package).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment