Steven's Blog

A Dream Land of Peace!

Ubuntu中删除孤立的包

After upgrading ubuntu to a new version, there will be many obsolete packages. To see these packages, you can

1
sudo apt-get upgrade

It will list all those obsolete packages.

To autoremove them one by one will be will tedious, we can first copy those packages into a file, like aa.txt, then use the following perl script to do it once:

1
2
3
4
5
6
7
use File::Slurp;
my @modules;
my $text = read_file('aa.txt', text_ref => 1);
@modules = grep {not /\s+/} split('[\s+]', $text);
foreach my $module (@modules){
	system("sudo apt-get autoremove $module");
}

Done!