CTO and co-founder of Signal Sciences. Author and speaker on software engineering, devops, and security.

Debian: find packages without reverse dependencies

Find all Debian packages that are either orphans, user commands or critical components.

When trying to make minimal OS, one wants to get rid of as many non-critical packages as possible. Under Debian, apt-cache rdepends --installed on a given package shows the reverse dependencies, or a list of other packages that depends on it.

The bash script below scans all installed packages and emits a list of packages without any reverse dependencies.

Packages without any reverse dependencies could be one of three things:

  1. Orphans - truly not used by anything. apt-get purge away.
  2. A top-level user command, something like wget
  3. Something critical for booting. Interestingly, bash comes up without reverse dependencies, but it's hard to imagine Debian booting without it.


# provides list of packages that have
# nothing depending on them
for target in `dpkg -l | grep '^ii' | awk '{ print \$2 }'`; do
   if [ "`apt-cache rdepends --installed $target | wc -l`" = "2" ]; then
      echo "$target"

© 2018 Nick Galbreath