Created
April 28, 2017 02:54
-
-
Save raphaeldussin/2800e85c6c5bcfb5f0208c28e6dc2624 to your computer and use it in GitHub Desktop.
purge ubuntu old kernels
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 | |
sudo apt-get update | |
sudo apt-get autoclean | |
sudo apt-get clean | |
sudo apt-get autoremove | |
kernel_pkgs=$( dpkg -l | grep -E 'linux-image-[0-9]' | awk '{ print $2 }' ) | |
current_kernel=$( uname -r ) | |
for pkg in $kernel_pkgs ; do | |
version=$( echo $pkg | sed -e "s/linux-image-//" ) | |
pkg_extra=$( echo $pkg | sed -e "s/linux-image-/linux-image-extra-/" ) | |
if [ ! $version == $current_kernel ] ; then | |
echo delete kernel $pkg | |
sudo dpkg --purge $pkg | |
sudo dpkg --purge $pkg_extra | |
sudo rm -Rf /usr/src/linux-headers-$version | |
sudo rm -Rf /usr/src/linux-headers-${version}-generic | |
else | |
echo keeping current kernel $pkg | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment