Note: leafpkgs is an obsolete and long abandoned project!

What is leafpks?

leafpkgs is a small utility written in Python that shows which packages in a Debian system are no longer necessary, or leaf packages, i.e. packages which no other packages depend on. leafpkgs takes virtual packages and version numbers into account.

leafpkgs reads the DPKG status database and shows the unneeded package names (with a short description) on its standard output. The (possibly edited) results of previous runs can be used in the following runs, so you can eliminate unwanted packages and all of the extra packages they came with.

With leafpkgs you can also select some specific packages to delete, and then see which packages become leaf packages, so you can remove them all.

Please note that leafpkgs never removes a package, it only figures out what would happen if some packages were removed.

Why should I need this tool?

Put simply, to keep a system clean. Debian comes with an amazing lot of packages. Your curiosity leads you to install and try packages you will eventually not use. Even if you remove those packages, they may have pulled in some other packages that remain in you system. Also, compiling source packages makes you install a lot of *-dev packages to satisfy its Build-Depends. This may not seem a big problem, but if you have a machine which is short of hard disk, or simply if you are as paranoid as me, this may be useful.

What is a leaf package?

A leaf package is an installed package that can be safely removed from the system without breaking dependencies (Pre-Depends, Depends, Recommends and/or Suggests). This includes:

  1. Packages which do not appear in any other package's dependency fields.
  2. Packages which do appear in other package's dependency fields but have a lower version than the one needed. Please note that, on a non-broken system, this can only happen with or'ed dependencies, or in Recommends or Suggests fields.

If the installed package provides a virtual package, then the virtual package should also be a leaf package.

Dependency types are hierachized into dependency levels, i.e. Depends (the lowest usable level) implies Pre-Depends, Recommends implies Depends, and Suggests implies Recommends.

NOTE REGARDING OR'ED DEPENDENCIES AND VIRTUAL PACKAGES: This program treats virtual packages and or'ed dependencies in a similar way. Let P be an installed package. Let O1 and O2 two installed packages such that P depends on O1 | O2 and the versions of these packages satisfy the ones needed by P. Let's suppose no other package depends on O1 nor O2. Then leafpkgs considers that none of O1 or O2 is a leaf package. Considering the removal of each package O1 and O2 separately, we would see that each package can be removed, for the other one is still installed. However, this would lead to considering both of them as leaf packages, which is certainly not correct.

The same goes for virtual packages. These packages can be seen as a frequently used, named or'ed dependency.

Installing leafpkgs

You can unpack the tar file and run leafpkgs in-place. You will need to have installed python-apt (which depends on Python 2.1).

You can install the package into your system using Distutils, which should be as easy as issuing:

python setup.py install

Take a look at Installing Python Modules on your Python documentation to learn more about Distutils. You may want to use the --prefix option not to mess things up. Of course, it would also be nice if someone packaged this into a nice .deb!

Running leafpkgs

In its simplest form, you can run leafpkgs simply by invoking it. It will take some time to read the status database, then it will print a list leaf packages. You can specify a particular dependency level by using the -d option. You can write the output to a file, then edit so that only the packages you want to remove remain in the file. Then you can feed this file to leafpkgs with the -x option to see which packages became leaf packages by removing the packages named in the file.

Another way to run leafpkgs is by specifying a list of leaf packages as arguments to the program. Then, the program will compute which packages in the system become leaves right after the deletion of the first ones.

You can filter which leaf packages to show using the options -I, -P and -S.

A simple example on using leafpkgs

Suppose you wanted to know which development packages are not required in your system. Then, you could issue:

$ leafpkgs | grep -- '-dev$'

You could also have used the option -S '.*devel' to avoid showing packages not in the development section. Note the use of .* in front of devel to include the development sections in non-US, contrib and non-free.

Another example on using leafpkgs

Imagine I want to delete the package cocoon (hey, nothig against it!). Then I'd like to know which packages I will not need when I remove it, so that I can also remove them. So I invoke:

$ leafpkgs -d suggests cocoon

So now:

# dpkg --purge cocoon cocoon-doc lib-openxml-java jserv

To do

Ivan Vilata i Balaguer