shell脚本学习之ubuntu删除多余内核

#!/bin/bash
#定期删除内核
#存储命令输出cmd_output=`commands`
uname_output=$(uname -r)
kernel_output=`dpkg --list|grep -Eo "linux\-image((\-extra)*)\-([0-9a-z\.\-]+\-generic)"`
for var in $kernel_output;do
	test=`echo $var|grep $uname_output`;
	if [ -z $test ];then
		read -p  "are you sure delete $var(yes?no):" flag;
		if test $flag = 'yes'; 
		then
			echo "开始删除内核$var"
			sudo apt-get purge $var
		else
			echo "未删除"
		fi
	fi		
done
sudo update-grub2
posted @ 2017-04-22 13:28  不被女生喜欢好多年  阅读(337)  评论(0编辑  收藏  举报