Adam's

adam@debian:~$ cat /dev/random

清理Debian内核和头文件的脚本

without comments

改自bones7456清理ubuntu内核的脚本, 原文地址在此: http://li2z.cn/2010/02/28/clean_ubuntu_kernel/.

Debian和Ubuntu的包命名方式稍有不同, 不能直接用, 改了下, 再就是避免删除元包, 增加了响应输入的功能.

有需要的直接拿去. 如果有修改, 最新的版本会发布在Github, 详见我的配置文件, Tips和脚本.

#!/bin/sh

CURRENT="`uname -r | awk -F"-" '{print $1"-"$2}'`"
HEADERS=""
IMAGES=""
ARCH="amd64"

for HEADER in `dpkg --get-selections | grep ^linux-headers | grep -v "${ARCH}" | awk -F"-" '{print $3"-"$4}'`
do
    if [[ "$CURRENT" < "$HEADER" ]]
    then
        echo "The running kernel is not the newest. $CURRENT < $HEADER"
        exit 1
    else
        [[ "$CURRENT" != "$HEADER" ]] && {
            HEADERS="${HEADERS} linux-headers-${HEADER}-${ARCH} linux-headers-${HEADER}-${ARCH}-common"
            IMAGE="`dpkg --get-selections | grep ^linux-image | grep "${HEADER}" | awk '{print $1}'`"
            IMAGES="${IMAGES} $IMAGE"
        }
    fi
done

if [[ -z "$HEADERS" ]]
then
    echo "There is no old kernel or headers need to be cleaned."
    exit 0
fi

echo
echo ------------------------------------
echo "$IMAGES $HEADERS"
echo ------------------------------------
echo 

read -p "Really wanna remove these packages? [y/N] " REPLY

case $REPLY in
    y | Y )
        sh -c "sudo apt-get purge $IMAGES $HEADERS" ;;
    * )
        echo "The operation is cancelled." ;;
esac

Written by adam8157

May 10th, 2010 at 8:25 pm

Posted in Linux,Tips

Tagged with ,

Leave a Reply