Skip to content

Instantly share code, notes, and snippets.

@vehrka
Created December 15, 2014 08:32
Show Gist options
  • Save vehrka/ce94fe69e774c5d2c8a2 to your computer and use it in GitHub Desktop.
Save vehrka/ce94fe69e774c5d2c8a2 to your computer and use it in GitHub Desktop.
Removing old kernels from Ubuntu
#!/bin/bash
if [ `id -u` -ne 0 ]; then
echo "Please run as root"
exit
else
kernelsv=`ls /boot | grep vmlinuz | cut -d'-' -f2,3`
nkernv=0
out=''
for kernv in ${kernelsv[@]}
do
out="$out FALSE $kernv"
nkernv=$(( $nkernv + 1 ))
done
height=$(( 100 + $nkernv * 30 ))
remkern=`zenity --list --checklist --separator=" " --height $height --column "Remove" --column "Kernel version" $out`
flag=0
for rmker in ${remkern[@]}
do
lista=`dpkg -l | grep ^ii | grep $rmker | awk -F' ' '{ print $2 }'`
zenity --question --text "Remove this packages?:\n\n$lista"
if [[ $? = 0 ]]; then
flag=1
echo "Removing $rmker"
lista=`dpkg -l | grep ^ii | grep $rmker | awk -F' ' '{ printf ("%s ", $2) }'`
apt-get --purge --yes remove $lista
fi
done
if [[ $flag = 1 ]]; then
update-grub
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment