Sunday, March 29, 2015

Remove all old linux kernels, headers and modules for Debian based systems

This has come up often for me with my linux machines, so I'll just blog a blog on the topic.  I came across two useful posts:

RemoveOldKernels

Ubuntu Cleanup: How to Remove All Unused Linux Kernel Headers, Images and Modules

The former is useful, but it only removes the kernels.  I want to remove all headers, etc. associated with them.  So, before I run the command from the latter blog post, I just want to confirm what I'm going to remove, as should you, with the following code (note, not as root just to be even more cautious):
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
 Perfect, now I can just run the one-liner from that latter blog post:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

Boom, I just got rid of over 3 GB's of old linux kernels on my system.

Monday, March 16, 2015

Python String Format Cookbook

As I'm tutoring someone through their introductory Computer Science course, I keep finding myself getting caught up in the Python 3 string formatting.  His assignments seem to focus a lot on how to print out various formats, and I'm still stuck in handling how they worked in Python 2.7.  I keep googling, and googling, and I often just find myself coming back to this reference.

Python String Format Cookbook

I'm just putting this up so that I can keep going back to this reference as I still adjust from Python 2 to Python 3.

EDIT: Just saw this cool writeup on Reddit: PyFormat.info