Linux达人写了一段程序:清理ubuntu的老内核脚本程序。当然也可以使用sudo aptitude purge ~ilinux-image-.*\(\!`uname -r`\) 删除旧内核,但是这段命令没有能把linux-headers-xxx删除掉。
下面是达人的脚本:[code]#!/bin/sh
# 清理ubuntu的老内核
# by bones7456
# http://li2z.cn
CURRENT="`uname -r | awk -F"-" '{print $1"-"$2}'`"
HEADERS=""
IMAGES=""
for HEADER in `dpkg --get-selections | grep ^linux-headers | \
grep -vE "(generic|386|virtual)" | awk '{gsub(/linux-headers-/,"",$1);print $1}'`
do
if [[ "$CURRENT" < "$HEADER" ]]
then
echo "正在运行的内核不是最新的。 $CURRENT < $HEADER"
echo "Running kernel is not the newest. $CURRENT < $HEADER"
exit 1
else
[[ "$CURRENT" != "$HEADER" ]] && {
HEADERS="${HEADERS} linux-headers-${HEADER}"
IMAGE="`dpkg --get-selections | grep ^linux-image | \
grep "${HEADER}" | awk '{print $1}'`"
IMAGES="${IMAGES} $IMAGE"
}
fi
done
if [[ x"$HEADERS" == x"" ]]
then
echo "没有要清理的老内核."
echo "No old kernel need to clean."
exit 0
fi
CMD="sudo apt-get purge $HEADERS $IMAGES"
echo "$CMD"
if [ "$1" == "-e" ]
then
sh -c "$CMD"
else
echo "请确定以上命令是否正确,然后输入 $0 -e 来执行以上命令。"
echo "Be sure this command is right, then type $0 -e to execute."
fi[/code]脚本程序结束。
thirty_wang 于 2014-09-12 20:16:34发表:
长知识了
菜菜123 于 2014-07-21 23:51:56发表:
学习