设为首页 加入收藏

TOP

Ubuntu删除旧内核的shell脚本
2014-11-24 00:35:34 来源: 作者: 【 】 浏览:2
Tags:Ubuntu 删除 内核 shell 脚本

#!/bin/sh
#Program:
# Let user uninstall unused kernels which installed as debian package form.
#Author:
# mtyy110
if [ "`whoami`" != 'root' ]; then
echo 'Requires superuser privilege.'
exit 1
fi
dpkg --get-selections | grep 'linux-' | grep -v 'deinstall' | grep "\-[0-9]\.[0-9]\{1,2\}\.[0-9]\{1,2\}\-"
while [ 1 ]
do
total=`dpkg --get-selections | grep 'linux-' | grep -v 'deinstall' | grep "\-[0-9]\.[0-9]\{1,2\}\.[0-9]\{1,2\}\-" | wc -l`
read -p "Which version would you like to uninstall (0 to quit)" version
if [ $version = "0" ]; then
break
fi
tmp=`echo $version | grep "^[0-9]\.[0-9]\{1,2\}\.[0-9]\{1,2\}\-\{0,1\}[0-9]\{0,2\}$" | wc -l`
if [ $tmp -eq 0 ]; then
echo "Not an available version format,please input full version."
continue
fi
sum=`dpkg --get-selections | grep 'linux-' | grep -v 'deinstall' | grep "\-[0-9]\.[0-9]\{1,2\}\.[0-9]\{1,2\}\-" | grep "$version" | wc -l`
if [ $sum -eq 0 ]; then
echo "Not find version $version.Ignored."
continue
fi
tmp=`uname -r | grep "$version" | wc -l`
if [ $tmp -eq 1 ]; then
read -p "This will uninstall the kernel current used:`uname -r`.Are you sure (y/N)" choice
if [ "$choice" != 'y' -a "$choice" != 'Y' ]; then
continue
fi
fi
if [ $total -le $sum ]; then
read -p "This will uninstall all the kernels in the system.Are you sure (y/N)" choice
if [ "$choice" -o 'y' -a "$choice" -o 'Y' ]; then
continue
fi
fi
apt-get remove `dpkg --get-selections | grep 'linux-' | grep -v 'deinstall' | grep "\-$version" | cut -f 1`
read -p "Continue to uninstall other kernel (Y/n)" choice
if [ "$choice" = 'n' -o "$choice" = 'N' ]; then
break
fi
dpkg --get-selections | grep 'linux-' | grep -v 'deinstall' | grep "\-[0-9]\.[0-9]\{1,2\}\.[0-9]\{1,2\}\-"
done
exit 0


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux系统中进程的状态 下一篇Linux-shell-||,&&{},(),reg-命令..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: