Ubuntu deletes the shell script of the old Kernel

Source: Internet
Author: User
Ubuntu deletes the shell script of the old kernel-general Linux technology-Linux programming and kernel information. The following is a detailed description. With the update of ubuntu, especially the update of its kernel, many versions of the kernel will remain in the system. You need to know that each version is very large, which not only wastes hard disk space, but also during startup, there will be many kernels in the grub option, which is very bad, so you need to delete the old version of the unused kernel. The shell script can help you easily solve the problem. This script is reprinted by senior student.
CODE :#! /Bin/sh
# Program:
# Let user uninstall unused kernels which installed as debian package form.
# Author:
# Mtyy110
If ["'whoam '"! = 'Root']; then
Echo 'requires superuser privilege .'
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 "Which version wocould you like to uninstall? (0 to quit) "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 "Not an available version format, please input full version ."
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 "Not find version $ version. Ignored ."
Continue
Fi
Tmp = 'uname-r | grep "$ version" | wc-l'
If [$ tmp-eq 1]; then
Read-p "This will uninstall the kernel current used: 'uname-R'. Are you sure? (Y/N) "choice
If ["$ choice "! = 'Y'-a "$ choice "! = 'Y']; then
Continue
Fi
Fi
If [$ total-le $ sum]; then
Read-p "This will uninstall all the kernels in the system. Are you sure? (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 "Continue to uninstall other kernel? (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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.