Clear old ubuntu kernel script programs

Source: Internet
Author: User
Clean up ubuntu's old kernel script program-General Linux technology-Linux programming and kernel information. The following is a detailed description. Linux experts wrote a program to clean up ubuntu's old kernel script program. Of course, you can also use sudo aptitude purge ~ Ilinux-image -.*\(\! 'Uname-r' \) deletes the old kernel, but this command cannot delete linux-headers-xxx.

The following is a daren script:
CODE :#! /Bin/sh
# Clearing old ubuntu kernels
# 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 "the running kernel is not up-to-date. $ 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 "no old kernel to be cleaned up ."
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 "make sure the preceding command is correct, and then enter $0-e to execute the preceding command. "
Echo "Be sure this command is right, then type $0-e to execute ."
Fi
Related Article

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.