删除Ubuntu Linux旧内核的方法
- yuzh652800
- 帖子: 686
- 注册时间: 2008-03-12 8:41
- 来自: nenu.Ani
-
- 帖子: 25
- 注册时间: 2008-04-26 23:27
- 联系:
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
Re: 删除Ubuntu Linux旧内核的方法
代码: 全选
sudo aptitude purge ~ilinux-.*\(\!`uname -r|cut -d- -f1-2`\)~i[0-9]
● 鸣学
- tenzu
- 论坛版主
- 帖子: 36924
- 注册时间: 2008-11-21 20:26
-
- 帖子: 20
- 注册时间: 2013-12-28 21:23
- 系统: Win7+Debian
- 来自: 天朝魔都
- 联系:
Re: 删除Ubuntu Linux旧内核的方法
这段命令写不出来。eexpress 写了:代码: 全选
sudo aptitude purge ~ilinux-.*\(\!`uname -r|cut -d- -f1-2`\)~i[0-9]
-
- 帖子: 80
- 注册时间: 2009-01-25 15:13
Re: 删除Ubuntu Linux旧内核的方法
eexpress 写了:代码: 全选
sudo aptitude purge ~ilinux-.*\(\!`uname -r|cut -d- -f1-2`\)~i[0-9]
已试用!确实神码!!!
- youzhiyili
- 帖子: 2422
- 注册时间: 2012-03-22 20:42
- 系统: ubuntu22.04
Re: 删除Ubuntu Linux旧内核的方法
呵呵,对比老外的方法,E神的的确最短
方法一:
方法二:
方法三:
方法四:(国产交互式的)

方法一:
代码: 全选
sudo apt-get -y purge $(dpkg --get-selections | awk '((/^linux-/) && (/[0-9]\./) && (!/'"`uname -r | sed "s/-generic//g"`"'/)) {print $1}')
代码: 全选
sudo dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
代码: 全选
#/bin/bash
ls /boot/ | grep vmlinuz | sed 's@vmlinuz-@linux-image-@g' | grep -v `uname -r` > /tmp/kernelList
for I in `cat /tmp/kernelList`
do
aptitude remove $I
done
rm -f /tmp/kernelList
update-grub
代码: 全选
#!/bin/bash
#Program:
# Let user uninstall unused kernels which installed as debian package form.
#Author:
# mtyy110
#ubuntu删除旧内核
dialog=whiptail
if [ "`whoami`" != 'root' ]; then
echo '需要root权限'
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 "要删除哪个版本?(0 退出)" 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 "格式不对,请输入正确的版本格式"
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 "没发现这个版本:$version"
continue
fi
tmp=`uname -r | grep "$version" | wc -l`
if [ $tmp -eq 1 ]; then
read -p "`uname -r` 是当前正在使用的内核,确定要删除?(y/N)" choice
if [ "$choice" != 'y' -a "$choice" != 'Y' ]; then
continue
fi
fi
if [ $total -le $sum ]; then
read -p "确定要卸载所有内核?(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 "是否继续删除其他的内核?(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
@自由建客 @qy117121 @枫叶饭团 @cikekid @YeLee @jtshs256 @eexpress @ljj_jjl2008 @zhw2101024 @TeliuTe @月下叹逍遥 @leeaman @懒蜗牛Gentoo @灰色小狼 @photor @adagio @JiangHui @phoenixlzx @oneleaf