In Debian every package depends on others and thus every package has generally at least another one which depends on it. Every once in a while you could need to know why a given package is present in your Debian machine. Here is how:
Method 1: apt-cache
$ apt-cache rdepends package
Shows all the packages, no matter whether they are installed or not, which depends on package.
Method 2: aptitude
If you, like me, don’t use aptitude very often (i.e. never) you should first update its package db:
# aptitude update
Then:
$ aptitude search '~i~Dpackage'
This command shows all the installed packages which depend on package.
Method 3: hand-made bash script
#!/bin/bash
# usage: ./irdeps.sh package [,package]
# show the packages which depend on a package and are installed
if [ $# -lt 1 ]; then
echo "Usage: $0 package"
exit -1;
fi
while [ "x$1" != "x" ];
do
echo "reverse dependencies for $1..."
while read pack;
do
if grep -q "^Package: ${pack/|/}$" /var/lib/dpkg/status;
then
awk -v pack=${pack/|/} '
/^Package: / && $2 == pack && flag==0{
flag=1;next
}
flag==1 && /^Status: /{
if ($4 == "installed")
print pack;
else
exit;
}' /var/lib/dpkg/status;
fi
done < <(apt-cache rdepends $1 | grep ^[[:space:]])
shift;
done
This script does the same of aptitude in about the same time, but it relies upon dpkg only (and bash+awk of course).
References: