Ubuntu – How to uninstall all but the default Ubuntu packages


I have a Dell Mini 9 with a 8 GB SSD. I installed Lucid some years ago, and upgraded each time, and now my hard disk is almost full. I see that new default programs get installed but old ones do not get automatically removed (e.g. Banshee and Rhythmbox). Now I can install a new distro from scratch but if there is a way to avoid the hassle, it would be great. I don't mind if the programs I have installed over the years get removed, they are only a few and I can reinstall them in a snap.

Best Answer

The solution to this question will probably solve your problem too.

Ubuntu pre-12.04

From a gnome-terminal do:

cat filesystem.manifest-desktop | awk '{print $1}' | sort > default.txt

This will get rid of the package versions and leave you with a sorted list default.txt containing all packages that are installed by default. As mentioned in the linked question, keep in mind that you might changed the default installation when installing updates and/or restricted packages during the installation of Ubuntu.

Ubuntu 12.04

The above step has changed a bit. To get a list of the packages that are initially installed, you need to unpack two files:

  1. filesystem.manifest
  2. filesystem.manifest-remove

To get what you want, you need to remove the latter from the former:

comm -3 <(cat filesystem.manifest | awk '{print $1}' | sort) <(cat filesystem.manifest-remove | sort) > default.txt

Now continue like pre-12.04:

dpkg --get-selections | awk '{print $1}' | sort > current.txt

This will get you a sorted list current.txt of all currently installed packages.

diff -u default.txt current.txt | grep "^+[^+]" | cut -c 2- > installed.txt
diff -u default.txt current.txt | grep "^-[^-]" | cut -c 2- > uninstalled.txt

This will get you the differences between the two package lists, where installed.txt contains all packages not part of the default installation, and uninstalled.txt contains all packages you are missing compared to a default installation.

Related Question