Skip to content

Instantly share code, notes, and snippets.

@mamrehn
Created October 6, 2014 17:55
Show Gist options
  • Save mamrehn/59a7a6431c18d76569fc to your computer and use it in GitHub Desktop.
Save mamrehn/59a7a6431c18d76569fc to your computer and use it in GitHub Desktop.
Frequent Linux (kernel) updates clutter the free disc space left on your hard drive. If everything works with the new version, delete the old ones with this small script.
#!/bin/sh
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
@mamrehn
Copy link
Author

mamrehn commented Oct 6, 2014

After this run 1,071 MB of disk space were freed on the system hdd.
Code first seen on the ubuntugenius blog.

$ 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
...
The following packages will be REMOVED:
  linux-headers-3.11.0-24* linux-headers-3.11.0-24-generic*
  linux-headers-3.13.0-32* linux-headers-3.13.0-32-generic*
  linux-headers-3.13.0-34* linux-headers-3.13.0-34-generic*
  linux-headers-3.13.0-35* linux-headers-3.13.0-35-generic*
  linux-image-3.11.0-24-generic* linux-image-3.13.0-32-generic*
  linux-image-3.13.0-34-generic* linux-image-3.13.0-35-generic*
  linux-image-extra-3.11.0-24-generic* linux-image-extra-3.13.0-32-generic*
  linux-image-extra-3.13.0-34-generic* linux-image-extra-3.13.0-35-generic*
0 upgraded, 0 newly installed, 16 to remove and 9 not upgraded.
After this operation, 1,071 MB disk space will be freed.
...
Removing linux-headers-3.11.0-24-generic (3.11.0-24.41) ...
Removing linux-headers-3.11.0-24 (3.11.0-24.41) ...
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment