标签:
ubuntu的内核经常升级,而老内核并不自动卸载.时间长了,就有一大堆内核垃圾,需要我们手动去清理.
xzc@xzc-HP-ProBook-4446s:~$ uname -a Linux xzc-HP-ProBook-4446s 3.13.0-46-generic #77-Ubuntu SMP Mon Mar 2 18:23:39 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
可见当前版本为3.13.0-46
xzc@xzc-HP-ProBook-4446s:~$ dpkg --get-selections|grep linux libselinux1:amd64 install linux-firmware install linux-generic install linux-headers-3.13.0-46 install linux-headers-3.13.0-46-generic install linux-headers-generic install linux-image-3.13.0-46-generic install linux-image-extra-3.13.0-44-generic deinstall linux-image-extra-3.13.0-46-generic install linux-image-generic install linux-libc-dev:amd64 install linux-signed-generic install linux-signed-image-3.13.0-44-generic deinstall linux-signed-image-3.13.0-46-generic install linux-signed-image-generic install linux-sound-base install pptp-linux install syslinux install syslinux-common install syslinux-legacy install util-linux install
其中linux-headers、linux-image、linux-signed开头的都是跟内核相关的.带有版本号的(如linux-image-extra-3.13.0-44-generic)才是可以删除的.注意不要删除当前使用的版本.后面的install表示已安装,deinstall表示曾经安装过,现在已被删除(已不占空间).
sudo apt-get purge linux-image-extra-3.13.0-44-generic
sudo apt-get purge linux-signed-image-3.13.0-44-generic
sudo apt-get purge linux-headers-3.13.0-44(这个好像会自动把linux-headers-3.13.0-46-generic删除,如果未删,则sudo apt-get purge linux-headers-3.13.0-46-generic)
注意不要使用sudo apt-get remove来删除,会出现linux-signed-image-3.13.0-44-generic deinstall.当然这时再运行purge也是可以删除的.
有网友用正则表达式写了一个脚本,没试过脚本效果怎么样:
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
标签:
原文地址:http://www.cnblogs.com/coding-my-life/p/4321022.html