Debian Package List – Listing Packages with Origin/Source in Debian

aptdebiandpkg

I want to list all packages of the form

$ dpkg -l libav\*

but in addition to this output, I would like the origin/source (I'm not sure of the preferred term) of each package. If the package doesn't correspond to any source, it should say unknown or similar. Off the top of my head, the most promising approach would be to use dctrl-tools, but I'm not sure how to go about it. For background, I was trying to debug a library mismatch with ffmpeg. See Debian bug report – ffmpeg: backport of 4:0.6.1-5 from unstable produces WARNING: library configuration mismatch. The bug report is no longer an issue, but I'm still interested in this question.

Just to be clear on the format, this should look something like

ii  libavahi-client-dev  0.6.27-2+squeeze1  Development files for the Avahi client library  squeeze
ii  libavcodec-dev       4:0.6.1-5          Development files for libavcodec                unstable

If the same package is available in multiple categories, ie. in both squeeze and testing, then the lowest / oldest category available should be used. In this case, squeeze.

Best Answer

Dpkg doesn't track this information. Where you got each .deb file is not its concern.

Apt doesn't track this information either, but it knows where you can now get the package, which is good enough.

As 9000 wrote in a comment, apt-cache policy '^libav' shows you what versions of packages with names matching the regexp ^libav are installed or available. The output isn't particularly convenient to parse, but here's a minimally tested script that gives approximately the format you want:

{ LC_CTYPE=C apt-cache policy '^libav'; echo .; } | perl -l -ne '
    if (!/^ /) {
        if (defined $version) {print "$package: $version unknown"}
        s/: *$//; $package=$_; $installed=1; $version=undef;
    }
    if (/^ *Installed: *\(none\)$/) {$installed=0}
    if ($installed && /^ \*+ +([^ ]+)/) {$version=$1}
    if (/^     [^ ]/) {$version=undef}
    if ($installed && defined $version && /^ +[0-9]+ +[^ ]+ +([^ \/]+)/) {
        print "$package: $version $1";
        $version=undef;
    }
'

Another way to the information you're asking for is with aptitude versions. Again, the minimally-tested snippet below gives roughly the desired format. The pattern "^libav" ~i matches packages that are installed and whose name matches the given regexp.

aptitude versions '"^libav" ~i' |
awk -vRS= '{if ($6 !~ /[^0-9]/) {$6="unknown"}
            print $3, $2, $5, $6}'

There's also a separately-packages utility apt-show-versions that, again, gives the information you want in roughly the format you're asking.

apt-show-versions | grep '^libav'
Related Question