Both answers already provided have their pros and cons.
Starting with debfoster
gives a list of packages which is simple to parse, so the following gives the requested result:
apt-cache policy $(debfoster -q -d tcpdump|tail -n +2)|awk '/^[^ ]/ { package=$0 } / Installed/ { print package " " $2 }'
using tail
to skip the first line and awk
to process the result in a single operation. (Using a command substitution avoids the need to process newlines.) Starting with debfoster
means we can only do this with a package which is already installed, so we can then use dpkg
to provide more information:
dpkg -l $(debfoster -q -d tcpdump|tail -n +2)
Starting with apt-rdepends
gives a list of packages which is a little harder to process, with duplicates; but it has the advantage of being able to process packages which aren't yet installed:
apt-cache policy $(apt-rdepends -p tcpdump 2>| /dev/null|awk '/Depends/ {print $2}'|sort -u)|awk '/^[^ ]/ { package=$0 } / Installed/ { print package " " $2 }'
This can also be used with dpkg -l
:
dpkg -l $(apt-rdepends -p tcpdump 2>| /dev/null|awk '/Depends/ {print $2}'|sort -u)
but this requires that dpkg
know about all the packages involved, which may not be the case if the package being processed isn't installed.
debfoster
includes Recommends
by default; this can be disabled using --option UseRecommends=no
:
debfoster -q --option UseRecommends=no -d tcpdump
apt-rdepends
doesn't include Recommends
by default; this can be enabled using -f Depends,PreDepends,Recommends -s Depends,PreDepends,Recommends
:
apt-rdepends -f Depends,PreDepends,Recommends -s Depends,PreDepends,Recommends -p tcpdump
although it doesn't give all the dependencies debfoster
finds in that case. (For example debfoster
finds that tcpdump
depends on apt
via libssl1.0.0
, debconf
and apt-utils
, but apt-rdepends
doesn't.)
tcpdump
andlibtext-wrapi18n-perl
andperl-base
. You write "recursively list a package's dependencies". Does that mean you want all the packages that "tcpdump" has a runtime dependency on? The immediate dependencies are given for example byapt-cache show tcpdump
, and areDepends: libc6 (>= 2.7), libpcap0.8 (>= 1.2.1), libssl1.0.0 (>= 1.0.0)
. Or do you want the reverse dependencies oftcpdump
, i.e. the packages that have a runtime dependency ontcpdump
? This is given byapt-cache rdepends tcpdump
. – Faheem Mitha Mar 09 '15 at 03:09apt-rdepends tcpdump
andapt-rdepends -r tcpdump
.apt-cache rdepends
seems kinda flakey; you might preferapt-rdepends
. – Faheem Mitha Mar 09 '15 at 03:14tcpdump
depends upon, and all of their dependencies, and all of their dependencies, etc. – detly Mar 09 '15 at 03:18apt-cache rdepends
shows reverse dependencies (aka. dependants). Very confusingly, it has a similar name toapt-rdepends
, which shows recursive dependencies. – detly Mar 09 '15 at 03:19apt-rdepends
show recursive dependencies.apt-rdepends -r
shows reverse recursive dependencies. Doesn't.apt-rdepends
work for you then? – Faheem Mitha Mar 09 '15 at 04:22