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 |