Skip to content

Instantly share code, notes, and snippets.

@krisek
Created July 12, 2025 11:11
Show Gist options
  • Save krisek/36e64d62115b49dfb5ba1c0ee3e31eac to your computer and use it in GitHub Desktop.
Save krisek/36e64d62115b49dfb5ba1c0ee3e31eac to your computer and use it in GitHub Desktop.
purge old kernels
#!/usr/bin/env bash
export PATH=$PATH:/usr/bin:/usr/sbin:/bin:/sbin
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment