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 packagesgrep linux-image
looks for the installed linux imagesawk '{ print $2 }'
just outputs the 2nd column (which is the package name)sort -V
puts the items in order by version numbersed -n '/'`uname -r`'/q;p'
prints the lines before the current kernelxargs sudo apt-get -y purge
purges the found kernelssed
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 expressionp
is print;
is the command separtor, so /something/q;p
says quit when you match something, else printsed -n '/'`uname -r`'/q;p'
is print the lines until it matches with the current kernel name.