Forked from grepwood/purge-other-kernels-than-current.sh
Last active
August 29, 2015 14:05
-
-
Save imranh2/7cc6906e9d6cc94e278d to your computer and use it in GitHub Desktop.
Revisions
-
imranh2 revised this gist
Aug 25, 2014 . 1 changed file with 33 additions and 27 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,30 +3,36 @@ CURRENT_KERNEL=`uname -r` OLD_KERNELS=`ls /usr/src/ -l | grep -v ">"| awk '{print $9}' | grep linux | grep -v $CURRENT_KERNEL | sed -r 's/^.{6}//'` AMOUNT_OF_OLD_KERNELS=`ls /usr/src/ -l | grep -v ">" | awk '{print $9}' | grep linux | grep -v $CURRENT_KERNEL | wc -l` echo "Amount of kernels to get rid of: $AMOUNT_OF_OLD_KERNELS" read -r -p "Are you sure? [y/N] " response if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] then for (( COUNTER=0; COUNTER<$AMOUNT_OF_OLD_KERNELS; COUNTER++ )) do HEAD=$((COUNTER+1)) DIR=`ls /usr/src/ -l | grep -v ">" | awk '{print $9}' | grep linux | grep -v $CURRENT_KERNEL | head -n$HEAD | tail -n1` echo -ne "Fetching package name of kernel #$HEAD... " # Gentoo only PACKAGE=`equery b $DIR | head -n+1` echo "done!" echo "Kernel #$HEAD is currently known as $PACKAGE" echo -ne "Removing kernel #$HEAD ..." # Gentoo only emerge -Cq $PACKAGE echo "done!" echo -ne "Removing kernel #$HEAD source directory... " rm -rf /usr/src/$DIR echo "done!" # Truncating the "linux-" from directory name so that we can find it in /boot and /lib/modules KERNEL=`echo $DIR | sed -r 's/^.{6}//'` echo -ne "Removing kernel #$HEAD from /boot... " rm -f /boot/*$KERNEL* echo "done!" echo -ne "Removing kernel #$HEAD modules... " rm -rf /lib/modules/$KERNEL echo "done!" echo "$PACKAGE has been purged from the system." done echo "All your old kernels have been purged. Have a nice day and remember to install Gentoo!" else echo "Quitting. No changes made." fi -
Michael Dec created this gist
Aug 25, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ #!/bin/bash CURRENT_KERNEL=`uname -r` OLD_KERNELS=`ls /usr/src/ -l | grep -v ">"| awk '{print $9}' | grep linux | grep -v $CURRENT_KERNEL | sed -r 's/^.{6}//'` AMOUNT_OF_OLD_KERNELS=`ls /usr/src/ -l | grep -v ">" | awk '{print $9}' | grep linux | grep -v $CURRENT_KERNEL | wc -l` echo "Amount of kernels to get rid of: $AMOUNT_OF_OLD_KERNELS" for (( COUNTER=0; COUNTER<$AMOUNT_OF_OLD_KERNELS; COUNTER++ )) do HEAD=$((COUNTER+1)) DIR=`ls /usr/src/ -l | grep -v ">" | awk '{print $9}' | grep linux | grep -v $CURRENT_KERNEL | head -n$HEAD | tail -n1` echo -ne "Fetching package name of kernel #$HEAD... " # Gentoo only PACKAGE=`equery b $DIR | head -n+1` echo "done!" echo "Kernel #$HEAD is currently known as $PACKAGE" echo -ne "Removing kernel #$HEAD ..." # Gentoo only emerge -Cq $PACKAGE echo "done!" echo -ne "Removing kernel #$HEAD source directory... " rm -rf /usr/src/$DIR echo "done!" # Truncating the "linux-" from directory name so that we can find it in /boot and /lib/modules KERNEL=`echo $DIR | sed -r 's/^.{6}//'` echo -ne "Removing kernel #$HEAD from /boot... " rm -f /boot/*$KERNEL* echo "done!" echo -ne "Removing kernel #$HEAD modules... " rm -rf /lib/modules/$KERNEL echo "done!" echo "$PACKAGE has been purged from the system." done echo "All your old kernels have been purged. Have a nice day and remember to install Gentoo!"