Thursday, July 19, 2012

Restore Ubuntu to the default settings without re-installing it

As a web developer (read app freak) I am always installing new IDEs, media players and libraries to try out. This madness cycle can definitely take a toll on your computer and slow it down to the point of no return.

Usually that is when you'd decide to format the computer and start anew. So when my wireless network was experiencing some hiccups and my computer will crash every 2 seconds for no reason or worse when it started using all of the swap memory I knew it was time to wipe it clean. Then I look at my home folder and I have over 300GB of data and I am kind of lazy. That is when I think to myself, no problem the home folder is in its own partition, right? Nope. It is not *BUMMER*

I don't want to re-install and reconfigure all of the programs I use but don't want to restart my computer every hour or so - that is when I remembered that some bash commands could save my day.

Currently I am using ubuntu 12.04 and I want to restore it to be the same it was when I first installed it, sure no problem let's start by getting two simple files from the ISO file (you still have the iso file right?):


casper/filesystem.manifest
casper/filesystem.manifest-remove

or just casper/filesystem.manifest-desktop for *buntu 11.10 or earlier
Now let's combine these 2 files:

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

If you have Ubuntu 11.10 or earlier then to get the default.txt file do:

cat filesystem.manifest-desktop | awk '{print $1}' | sort > default.txt
default.txt contains a sorted list of all the programs our default installation should include. Now let's get the software currently installed in our computer:

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

If we diff the default software vs what is currently installed, we can get what was added:


 diff -u default.txt currently_installed.txt | grep "^+[^+]" | cut -c 2- > additions.txt
or what was removed:

diff -u default.txt currently_installed.txt | grep "^-[^-]" | cut -c 2- > removed.txt
Now if we want to remove all of the additions, including the configuration files:

sudo apt-get purge $(cat additions.txt)
To add back the files we removed:

sudo apt-get install $(cat removed.txt)

Remove the configuration files:


rm -rf .gnome .gnome2 .gconf .gconfd .metacity
That should bring your current ubuntu based to the default state (I believe it should work with every Linux Distro, but the judge is still out there).

This is a bit radical though, before removing any files make sure that you only remove anything that you don't want to keep. And just in case, make a backup of your files just in case.

No comments: