Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an a few machines that I was planning to run in a cluster, but have decided after some testing to configure them differently. The partitions and Ubuntu install are still as I want them, but it would be nice to have them back to a clean state without having to re-install them all.

share|improve this question
up vote 4 down vote accepted

I actually had to do this a while back (a couple years ago, so excuse the not quite perfect commands) and this is what I did.


dpkg --get-selections > installed.txt

I then happened to have a fresh installation around that I did the same thing on. If you don't have one, you could probably find a list somewhere for your distribution. Then:

sdiff [your install list] [clean install list] --suppress-common-lines > differences.txt
sdiff [clean install list] [differences] --suppress-common-lines > remove.txt

The second sdiff is to allow for default packages you might have removed from your installation. Just wanted to avoid more errors then necessary. The next part is really whatever your favorite method for search and replace is, I like vim so that's what I used.


This is because the dkpg leaves the install word after every package in the list, and we don't want that. I also ran a couple more commands in vim to remove excess white space and replace the line breaks with spaces, just to make it a bit cleaner. You then run this file through apt-get remove (add in --purge if you want).

If you want to be extra thorough you can use different cleaners to get rid of crap, and also run the comparison differently so you can add the packages back that you may have removed [from the default package list].

All in all, after I did all that I decided it wasn't worth the effort compared to the relative ease of reinstalling Ubuntu.

share|improve this answer
Will this also reset all systemwide configuration files? – Eliah Kagan Jun 6 '12 at 19:45
No (unless you purge and reinstall everything with modified configs), so like I said at the end, really more of a headache than it's worth. I have found a script here that seems to remove some of that headache for config files. (disclaimer: I have never tried this script before, just found it in a google search) – hamalnamal Jun 6 '12 at 19:55
sudo dpkg -i /var/cache/apt/archives/*.deb
sudo dpkg --configure -a  

And then, if something was broken, run a couple of times:

sudo apt-get install -f
sudo dpkg --configure -a
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.