For both systems I did:
in order to get a list of installed packages.
dpkg -l | grep ^ii | sed 's_ _\t_g' | cut -f 2 > installed-pkgs
Then I named one file o and the other n. (o is cleaned up install, n is new install)
After this I sorted both files with:
After this operation I ran
sort -o so o
sort -o sn n
in order to sort out the packages which are installed on both systems.
comm -31 so sn >> in-sn-notin-so.txt
comm -32 so sn >> in-so-notin-sn.txt
"in-sn-notin-so.txt" contains the packages which are missing on the cleaned up install, but are part of a new install (I decided to install these)
"in-so-notin-sn.txt" contains the packages which are on the cleaned up install, but are not part of a new install. This packages are the ones we want to remove.
!!!! But we have to be careful, as I noticed, that the clean install had a different kernel version, so we have to modify both files and remove the lines beginning with "linux-".
As these are many packages and we want pack them in one command "sudo apt-get --purge remove ... "
we have to transform the files consisting of many lines in a file, containing all these packages in one line. This is done with:
So finally I modifed remove.sh to:
tr '\n' ' ' < in-sn-notin-so.txt > install.sh
tr '\n' ' ' < in-so-notin-sn.txt > remove.sh
and made it executable (chmod u+x remove.sh) . I did the same with "apt-get install" for the file install.sh.
apt-get --purge remove (here comes the content of remove.sh)
After I ran both scripts finally both installs had the same size, so cleaning up the old system was sucessful!
After all I ask myself why all these packages were not removed (as these packages were not deliberately installed, so they were dependencies) by the "apt-get --purge remove" command? For example I have never installes "apache2-utils" etc.
An explanation would be, that I have installed packages from ppa (but not many) and apt-get can not find or uninstall all the dependencies?
What can I do in order to prevent these things in the future? It seems apt-get is not fully capable of removing all dependencies coming with one package, is there a better alternative?
What to do in order to remove all dependencies while removing an application.?
I could write a script similar to the way we cleaned up the install, which captures the difference of installed packages while installing and then removes all this, when I want to remove the package. But is there a better way?
Thank you for all your help and ideas!