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 |