A Debian package reverse dependency finder

Update: 9/26/2004: One of the Debian guys tipped me off to the existence of a Debian package that is intended to find orphaned libraries/packages: deborphan. Deborphan is likely to be a much better solution to this problem, so please look there first before considering my little perl hack. :)


So, if you run Debian, you may have a need to occasionally find out what packages (debs) are installed and no longer have reverse dependencies. This is especially relevant to *-dev packages and library packages.

If you happen to install a package, perhaps just to try it out, and later decide to uninstall it, Debian has no straightforward way (that I know of anyway, if I'm wrong, please let me know) to automatically remove all other packages that were installed at the same time.

This is one of the primary, or perhaps only problems with Debian's apt system. Over time, the install base for heavy desktop/experimental/unstable use tends to grow.

Some time ago I built the debian reverse dependency checker. The idea was to get a quick list of installed packages and a count of how many other currently installed packages depend on each.


Let's get right to it. Here's a little 41 line perl script that you may or may not find useful. - 41 lines, 1109 bytes


The script is pretty straightforward. Run it as root (otherwise dpkg will likely complain) and it will start crunching. The general idea is that it first gets a list of all installed packages, and then runs "dpkg --no-act --purge" (fake package removal) on each package. In the event that the package has reverse dependencies (other packages that depend on it), dpkg gives a complaint, and the script uses this complaint message to count reverse dependencies.

Because the local dpkg database is searched multiple times for each package, the script is slow and completely inefficient. Hopefully it's not something you need to run too often. I generally redirect output to a file and use it later to remove unnecessary or otherwise unwanted packages. I should also point out that if the format of any dpkg output is changed, this script is likely to not work properly.

If you like it or hate it or know of better or similar alternatives, feel free to let me know. Enjoy!