Clean up small scripts in the old Ubuntu Kernel

Source: Internet
Author: User
Ubuntu has been used for a long time. After several kernel upgrades, it will inevitably need to clean up the old kernel. After all, a set of kernel will have more than 170 MB of space. However, it is also annoying to write a pile of words each time to clean up. Although Ubuntu command skills (here I would like to say a few more: If Ubuntu er hasn't read this yet, I strongly recommend you read it again .) There is a command to delete the old kernel, and there is a line: sudoaptitudepurge ~ Ilinux-image -.*\(\! 'Uname-R' \) but I am not

Ubuntu has been used for a long time. After several kernel upgrades, it will inevitably need to clean up the old kernel. After all, a set of kernel will have more than 170 MB of space. However, it is also annoying to write a pile of words each time to clean up. Although Ubuntu command skills (here I would like to say a few more: If Ubuntu er hasn't read this yet, I strongly recommend you read it again .) There is a command to delete the old kernel, and just one line:

sudo aptitude purge ~ilinux-image-.*\(\!`uname -r`\)

But I do not like it very much, because this does not delete linux-headers-xxx.
As a result, I wrote a complex one, and I can save what I need so that I don't need it.

#! /Bin/sh# Clearing old ubuntu kernels# By bones7456# Http://li2z.cnCURRENT="'Uname-r | awk-F "-" '{print $1 "-" $2 }''"HEADERS=""IMAGES=""ForHEADERIn `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"        }    FiDone If [[X"$ HEADERS"= X"" ]]Then    Echo "No old kernel to be cleaned up ."    Echo "No old kernel need to clean ."    Exit 0FiCMD="Sudo apt-get purge$ HEADERS $ IMAGES"Echo "$ CMD"If [ "$1"="-E" ]Then    Sh -C "$ CMD"Else    Echo "Check whether the preceding commands are correct and enter $0-e to execute the preceding commands. "    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.