Skip to content

Instantly share code, notes, and snippets.

@woods
Last active May 31, 2019 22:17
Show Gist options
  • Save woods/43b82cc0e4dfe3ebeca3b7d2c6167a6a to your computer and use it in GitHub Desktop.
Save woods/43b82cc0e4dfe3ebeca3b7d2c6167a6a to your computer and use it in GitHub Desktop.
Purge unused kernel packages on Ubuntu 14.04
# Get all patch versions of all kernels on the system
all_kernel_patch_versions=$( dpkg -l | egrep 'linux-headers-3.13.0-[0-9]+-generic' | awk -F '-' '{print $4}' | sort -n )
# Exclude any kernels that are in use (hard coded; you must CUSTOMIZE THIS PER MACHINE)
unused_kernel_patch_versions=$( echo "$all_kernel_patch_versions" | egrep -v '1[67]' )
for n in $unused_kernel_patch_versions ; do
echo
echo "========== $n ========="
echo
dpkg --purge linux-image-3.13.0-${n}-generic linux-image-extra-3.13.0-${n}-generic linux-headers-3.13.0-${n}-generic linux-headers-3.13.0-${n}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment