Removing old kernel

2016-03-12 :: ( 2 minutes reading )

When upgrading ubuntu, sometimes it failed because of insufficient disk on boot. This could be caused by too many kernel installed on the machine.

Command to remove old kernel from here

dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p' | xargs sudo apt-get -y purge

dpkg –list | grep linux-image | awk ‘{ print $2 }’ | sort -V | sed -n ‘/'uname -r'/q;p’ | xargs sudo apt-get -y purgenation (remember, | uses the output of the previous command as the input to the next)

  • dpkg --list lists all installed packages
  • grep linux-image looks for the installed linux images
  • awk '{ print $2 }' just outputs the 2nd column (which is the package name)
  • sort -V puts the items in order by version number
  • sed -n '/'`uname -r`'/q;p' prints the lines before the current kernel
  • xargs sudo apt-get -y purge purges the found kernels

Unwinding the sed invocation:

  • -n tells sed to be quiet
  • `uname -r` outputs the current installed kernel release - we include it in backticks so that the output is includes as part of the command (you might also see this as $(uname -r)
  • /something/q says stop when you match ‘something’ (in this case, something is output of uname -r) - the / surround a regular expression
  • p is print
  • the ; is the command separtor, so /something/q;p says quit when you match something, else print

altogether, sed -n '/'`uname -r`'/q;p' is print the lines until it matches with the current kernel name.

comments powered by Disqus

Archives

English

  • My Desktop With i3, polybar, conky, and rofi
  • Convert Intellij Live Template to vscode Snippet
  • Why for-range behaves differently depending on the size of the element (A peek into go compiler optimization)
  • Testing go 1.5 cross compilation on raspberry pi
  • osx-push-to-talk App
  • Tracking origin of bugs with git bisect
  • Stubbing Time.Now() in golang
  • My account just got hacked by Romanian (Possibly)
  • berks upload core dump
  • Safely sharing credentials with PGP

Indonesia

  • Ruby Fiber apaan sih ?
  • Scale MongoDB dengan Sharding
  • Telepon murah ke Indonesia dengan voip

Today I Learned

  • Intellij as git diff and mergetool
  • Checksum a File From a URL
  • Global Gitignore File
  • View kubernetes secret
  • Push Only Current Branch
  • Convert PDF to Text Using OCR
  • Checkout Last Branch
  • Replacing Last Command and Execute It
  • Open Last Command in the Editor With Fc
  • Regex for Validating Password
Labs.Yulrizka.com
twitter github feed
    • Left Panel
    • No Panel
    • Right Panel
  • Home
  • EN
  • ID
  • Today I Learned

© Ahmy Yulrizka 2019. Made with hugo source