I have a list of packages on my system, that were installed and removed again, but not purged, i.e. there are still a lot of conffiles etc. laying around.
The output of dpkg --get-selections | grep deinstall
lists about 85 different packages which I don't need and want to be purged entirely.
So my short question, which I decided to finally ask after experimenting around has lead to this problem, is:
How do I completely purge previously installed packages that are already removed?
Reinstalling and then purging is not an option, of course.
I just found the following command which worked:
dpkg --get-selections | grep deinstall
produces a list of package names with the word "deinstall
":By asking
awk
to print only the first field we get:Now that we have the list of packages,
xargs
will let us feed the list of packages to a command (or commands, if the list is long enough):When you are happy with the simulated results, replace
--dry-run
with-y
in theapt-get
command.Relevant documentation:
If you just want to purge the whole list, you can use this command; it will perform a dry run, in case essential packages are going to be removed, which you probably don't want to happen:
If no essential package is going to be removed, it's safe to run the actual command:
sed -n 's/\tdeinstall$//p'
: prints only lines instdin
where a tabulation followed by adeinstall
string could be removed from the end of the line; this has the effect of printing only the lines containing a tabulation followed by adeinstall
string at the end of the line without the actual tabulation followed by thedeinstall
string at the end of the linexargs sudo apt-get --yes purge
: passes each line instdin
as an argument tosudo apt-get --yes purge
My fifty cents, a simple oneliner:
First test with
and bye bye
Example
I asked this myself a couple of days ago. Came up with
The removed but not purged packages appear in the output of
dpkg -l
withrc
at the beginning.awk
picks out the second column aka the name of the package and prints them space-separated.