Monday, 6 December 2010

How to remove Old Ubuntu Kernels in a single command.

On Ubuntu you amass a load of old kernels over time. There are a lot of guides on the net on how to remove kernels, but none of them give me the pithy and succinct one liner that just does the job in the least amount of keystrokes.

Or worse they remove something they shouldn't do.

Here's my entry as the easiest way to get rid of those kernels, without removing other packages. For those of a cautious disposition use 'search' instead of 'purge' to see the list of things that will be removed first :-)

sudo aptitude purge '~ilinux-image-[0-9].* !'`uname -r`

Thursday, 2 December 2010

Sparse copying from a pipe on Linux with cp

One of the annoying 'missing options' on gzip and bzip is one to write the file out in a sparse fashion. This is particularly irritating when you're manipulating virtual machine images - which are often 90%+ empty space.

So you try and pipe it into 'cp --sparse=always' and you find that it can't read from stdin natively.

Then you scratch your head for several months. Or search the internet for 'sparsifiers' - with little success.

And finally you stumble across the answer, which was staring you in the face all along.

zcat -f "$in" | cp --sparse=always /dev/stdin "$out"

I offer this to the Google gods in the hope that others find it faster than I did.