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