Spring Cleaning Debian

This is a quick post about removing clutter that accumulates sooner or later in the form of programs you installed once and forgot.

Or more positively: From time to time it's nice to clean up unused programs.

Typically it is good to use a GUI if you have one, so check the menu, obviously. But: not all programs have an entry there. So we have to dig deeper.

But first, let's get the low-hanging fruits:

Use apt-get's autoremove to remove packages that were installed as dependencies for stuff you don't have anymore. Totally cool. clean your cache and check that your dependencies are alright.

Check the output of deborphan and decide what to keep. I never had a broken system when I directly removed orphaned packages. This is different than apt-get's autoremove, because you might installed useful tools such as mr or the lovely inconsolata-font explicitly and they don't have a parent, but they are not cruft either.

Update

I am using a much simpler method now. I am regularly creating a file that contains all manually installed packages. This happens via this script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#!/bin/bash

# write packages to a list managet by etckeeper
# http://askubuntu.com/a/492343
# https://wiki.archlinux.org/index.php/Etckeeper
# this is ment to be a git-hook

## write the currently installed packages to a file
PACKAGES_DIR=/etc
PACKAGES_FILE=${PACKAGES_DIR}/.packages
APTMARK="apt-mark showmanual | sort -u"
INITIAL_STATUS=/var/log/installer/initial-status.gz
if [ -f $INITIAL_STATUS ]; then
    comm -23 <(eval "$APTMARK") <(gzip -dc ${INITIAL_STATUS} | sed -n 's/^Package: //p' | sort -u) > $PACKAGES_FILE
else
    eval "$APTMARK" > $PACKAGES_FILE
fi

The file is managed via etckeeper which is configured to push to my NAS. The nice thing is: this list is significantly smaller and I have multiple versions of it.

How to get more details about installed packages?

List all packages sorted by priority (this is not really important because the output of the above script lists all manually installed packages):

dpkg-query -Wf '${Package;-40}${Priority}\n' | sort -b -k2 | less

Dependencies

Do reverse dependency checking for a given package FOO:

apt-cache rdepends FOO

What does a package do?

Find out what an installed package FOO does:

dpkg -l FOO

Now you have all the information for each package and can decide whether to keep it or to remove it. Bonus: You know exactly what will be removed as well.