sh 如果有两个以上可用,则删除最旧的Linux内核和相关软件包。 #bash #linux #bash-select #kernel

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 如果有两个以上可用,则删除最旧的Linux内核和相关软件包。 #bash #linux #bash-select #kernel相关的知识,希望对你有一定的参考价值。

#!/bin/bash 

KERNELS=`ls /boot | grep vmlinuz | cut -d'-' -f2,3`
echo Available kernels: $KERNELS
KERNCOUNT=`echo $KERNELS | wc -w`
if [ $KERNCOUNT -gt 2 ]; 
then
	OLDEST=`echo "${KERNELS%% *}" | head -1`
	PACKAGES=`dpkg -l | grep ^ii |grep $OLDEST | awk -F' ' '{ print $2 }'`
	echo "Oldest package (to be removed): $OLDEST"
	echo These packages will be removed: $PACKAGES
	echo Proceed?
	PS3="Select: "
	select yn in Yes No; 
	do
		case $yn in 
			Yes) 
				echo "Proceed";break
				;;
		        *) 
				exit
				;;
		esac
	done
	sudo apt-get remove -y $PACKAGES
	echo Done removing oldest kernel
else
	echo There are only two kernels in the system. Aborting.
fi

以上是关于sh 如果有两个以上可用,则删除最旧的Linux内核和相关软件包。 #bash #linux #bash-select #kernel的主要内容,如果未能解决你的问题,请参考以下文章