Created
June 3, 2022 16:35
-
-
Save meschbach/571a6dcfd341b6d320d9b278dc92317c to your computer and use it in GitHub Desktop.
Ubuntu Kernel Cleanup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
# Removes kernels + headers remaining on a ubuntu machine. | |
current_version=$(uname -a |awk '{print substr($3, 1, length($3)-length("-generic"));}') | |
echo "Current Kernel: $current_version" | |
installed=$(dpkg-query -l | grep '^ii' | awk '{print $2}') | |
headers=$(grep linux-headers- <<<"$installed" |head -n -3 |grep -v "$current_version") | |
modules=$(grep linux-modules <<<"$installed" |grep -v "extra" |head -n -2 |grep -v "$current_version") | |
extras=$(grep linux-modules-extra <<<"$installed" |head -n -2 |grep -v "$current_version") | |
echo "Removing" | |
echo $headers $modules $extras | |
set -xe | |
echo $headers $modules $extras | xargs sudo aptitude purge -y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment