For both systems I did:
Code:
dpkg -l | grep ^ii | sed 's_ _\t_g' | cut -f 2 > installed-pkgs
in order to get a list of installed packages.
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:
Code:
sort -o so o
sort -o sn n
After this operation I ran
Code:
comm -31 so sn >> in-sn-notin-so.txt
comm -32 so sn >> in-so-notin-sn.txt
in order to sort out the packages which are installed on both systems.
"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:
Code:
tr '\n' ' ' < in-sn-notin-so.txt > install.sh
tr '\n' ' ' < in-so-notin-sn.txt > remove.sh
So finally I modifed remove.sh to:
Code:
#! /bin/bash
apt-get --purge remove (here comes the content of remove.sh)
and made it executable (chmod u+x remove.sh) . I did the same with "apt-get install" for the file install.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!
Bookmarks