This page looks best with JavaScript enabled

Cleanup Unused Package Configs

 ·  ☕ 2 min read

Background

You have added a few apps from the debian repo and no longer need then - actually you’ve already uninstalled them but you forgot to --purge when you apt-get remove the app. This post provides a quick script to cleanup any app (package) that has remnant config data residing after a remove of an app.

As you remove packages (apt-get remove xxx) in debian the configuration files for the package are not automatically removed (note: you can use the --purge flag to remove config files with the removal of the app). Over time this can add up and/or you may want to remove the configs to force a clean install.

Details

A very useful script to cleanup (purge) package remnants (e.g. config files associated with packages):

1
$ apt-get purge `dpkg --get-selections | grep deinstall | cut -f1`

note: the script will prompt you on what it will purge prior to the purge

Breakdown of the script:

  • dpkg --get-selections | grep deinstall | cut -f1: this grabs a list of all packages that are marked as ‘deinstall’ in dpkg and passing this list to apt-get purge which will remove them.

Notes

If you would like to verify or view more things you can always dump the results of the dpkg command to a file, verify the file, then read the file in to apt-get purge.

1
2
$ dpkg --get-selections | grep deinstall | cut -f1 > cleanup.lst
$ apt-get purge `cat cleanup.lst`

I’ve also ran across the need to manually review all installed packages and remove unneeded items. You can quickly do that with the following:

1
$ dpkg --get-selections > review.lst

Now open the review.lst file in your favorite text editor and mark each row you
want to remove (I typically change INSTALL to UNINSTALL); for example, if I wanted to uninstall zip I would use:

1
2
3
4
...
zenity                                          install
zip                                             uninstall
...

Next, I can simply grep through the file on uninstall to remove all packages that I’ve marked as uninstall:

1
$ apt-get purge `cat review.lst | grep uninstall | cut -f1`
Share on

drad
WRITTEN BY
drad
Sr. Consultant