脚本清理ubuntu的老内核:有错误求修正!!
Tofloor
poster avatar
Coollove
deepin
2012-04-21 22:39
Author
  1. #!/bin/sh
  2. #
  3. # 清理ubuntu的老内核
  4. #sudo aptitude purge ~ilinux-image-.*\(\!`uname -r`\)
  5. CURRENT="`uname -r | awk -F"-" '{print $1"-"$2}'`"
  6. HEADERS=""
  7. IMAGES=""
  8. for HEADER in `dpkg --get-selections | grep ^linux-headers | \
  9. grep -vE "(generic|386|virtual)" | awk '{gsub(/linux-headers-/,"",$1);print $1}'`
  10. do
  11.     if [[ "$CURRENT" < "$HEADER" ]]
  12.     then
  13.         echo "正在运行的内核不是最新的。 $CURRENT < $HEADER"
  14.         echo "Running kernel is not the newest. $CURRENT < $HEADER"
  15.         exit 1
  16.     else
  17.         [[ "$CURRENT" != "$HEADER" ]] && {
  18.             HEADERS="${HEADERS} linux-headers-${HEADER}"
  19.             IMAGE="`dpkg --get-selections | grep ^linux-image | \
  20.                 grep "${HEADER}" | awk '{print $1}'`"
  21.             IMAGES="${IMAGES} $IMAGE"
  22.         }
  23.     fi
  24. done
  25. if [[ x"$HEADERS" == x"" ]]
  26. then
  27.     echo "没有要清理的老内核."
  28.     echo "No old kernel need to clean."
  29.     exit 0
  30. fi
  31. CMD="sudo apt-get purge $HEADERS $IMAGES"
  32. echo "$CMD"
  33. if [ "$1" == "-e" ]
  34. then
  35.     sh -c "$CMD"
  36. else
  37.     echo "请确定以上命令是否正确,然后输入 $0 -e 来执行以上命令。"
  38.     echo "Be sure this command is right, then type $0 -e to execute."
  39. fi
Copy the Code
Reply Favorite View the author
All Replies
cxbii
deepin
2012-04-22 02:00
#1
记得ubuntu tweak有这个功能,用它删除应该安全点
Reply View the author
tuhaihe
deepin
2012-04-22 23:20
#2
赞!最近正在学习脚本,这个可以拿来学习。
Reply View the author
cxbii
deepin
2012-04-23 01:15
#3
ok。修复好后
添加之推荐脚本!
Reply View the author