Skip to content

Instantly share code, notes, and snippets.

@vitaliel
Created November 6, 2013 07:14
Show Gist options
  • Save vitaliel/7332183 to your computer and use it in GitHub Desktop.
Save vitaliel/7332183 to your computer and use it in GitHub Desktop.
Remove old linux packages from ubuntu/debian
keep=%w{3.5.0-41 3.5.0-42}
versions = Dir['/boot/System.map*'].sort.map do |f|
name = File.basename(f)
if name =~ /(\d+\.\d+\.\d+-\d+)/
$1
end
end
pkgs = []
(versions-keep).each do |ver|
pkgs << "linux-image-#{ver}-generic"
pkgs << "linux-image-extra-#{ver}-generic"
pkgs << "linux-headers-#{ver}-generic"
end
all=`dpkg -l | grep 'linux-'`.split(/\n/).map {|line| line.split(/\s+/, 5)}.select {|el| el[1] =~ /linux-(image|headers)/}
#p all
installed = all.map {|e| e[1]}
missing = pkgs - installed
puts 'Missing'
p missing
pkgs -= missing
c = 'sudo apt-get purge ' + pkgs.join(' ')
puts c
system c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment