How to get information about deb package archive?

How to get information about .deb package archive?

Like: package information, version, installed-size, architecture, description and licensing information etc. from .deb package archive?

Asked By: Pandya

||

You can use dpkg-deb command to manipulate Debian package archive (.deb).

From manpage:-

-I, --info archive [control-file-name...]
              Provides information about a binary package archive.

              If  no  control-file-names are specified then it will print a summary of the contents of the package as
              well as its control file.

              If any control-file-names are specified then dpkg-deb will print them in the order they were specified;
              if  any  of  the components weren't present it will print an error message to stderr about each one and
              exit with status 2.

Example Usage:-

$ dpkg-deb -I intltool_0.50.2-2_all.deb 
 new debian package, version 2.0.
 size 52040 bytes: control archive=1242 bytes.
     831 bytes,    19 lines      control              
    1189 bytes,    18 lines      md5sums              
 Package: intltool
 Version: 0.50.2-2
 Architecture: all
 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
 Original-Maintainer: Debian GNOME Maintainers <pkg-gnome-maintainers@lists.alioth.debian.org>
 Installed-Size: 239
 Depends: gettext (>= 0.10.36-1), patch, automake | automaken, perl (>= 5.8.1), libxml-parser-perl, file
 Provides: xml-i18n-tools
 Section: devel
 Priority: optional
 Multi-Arch: foreign
 Homepage: https://launchpad.net/intltool
 Description: Utility scripts for internationalizing XML
  Automatically extracts translatable strings from oaf, glade, bonobo
  ui, nautilus theme and other XML files into the po files.
  .
  Automatically merges translations from po files back into .oaf files
  (encoding to be 7-bit clean). The merging mechanism can also be
  extended to support other types of XML files.

You can list the content by dpkg-deb -c:-

Example Usage:

$ dpkg-deb -c libnotify-bin_0.7.6-1ubuntu3_i386.deb 
drwxr-xr-x root/root         0 2014-02-22 05:24 ./
drwxr-xr-x root/root         0 2014-02-22 05:24 ./usr/
drwxr-xr-x root/root         0 2014-02-22 05:24 ./usr/bin/
-rwxr-xr-x root/root      9764 2014-02-22 05:24 ./usr/bin/notify-send
drwxr-xr-x root/root         0 2014-02-22 05:24 ./usr/share/
drwxr-xr-x root/root         0 2014-02-22 05:24 ./usr/share/man/
drwxr-xr-x root/root         0 2014-02-22 05:24 ./usr/share/man/man1/
-rw-r--r-- root/root       773 2014-02-22 05:24 ./usr/share/man/man1/notify-send.1.gz
drwxr-xr-x root/root         0 2014-02-22 05:24 ./usr/share/doc/
drwxr-xr-x root/root         0 2014-02-22 05:25 ./usr/share/doc/libnotify-bin/
-rw-r--r-- root/root      1327 2011-07-31 03:11 ./usr/share/doc/libnotify-bin/copyright
lrwxrwxrwx root/root         0 2014-02-22 05:25 ./usr/share/doc/libnotify-bin/AUTHORS -> ../libnotify4/AUTHORS
lrwxrwxrwx root/root         0 2014-02-22 05:25 ./usr/share/doc/libnotify-bin/NEWS.gz -> ../libnotify4/NEWS.gz
lrwxrwxrwx root/root         0 2014-02-22 05:25 ./usr/share/doc/libnotify-bin/changelog.Debian.gz -> ../libnotify4/changelog.Debian.gz

Getting licensing information:-

Most of archive’s copyright information is available from /usr/share/doc/<pkgname>/copyright

Example :-

$ dpkg-deb -c gparted_0.18.0-1_i386.deb | grep -i copyright
-rw-r--r-- root/root      1067 2011-12-08 00:34 ./usr/share/doc/gparted/copyright

Which you can extract by -x and look for License under which it is released.

Here:-

$ cat /usr/share/doc/gparted/copyright | grep -i ^license -A 5
License:

   This package is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 dated June, 1991.

For more, run man dpkg-deb.

Answered By: Pandya

You can use dpkg -f (archive) (field name) to do exactly this.

Example:

dpkg -f archive.deb Version
dpkg -f archive.deb Package

To get possible field names:

dpkg --info archive.deb
Answered By: laughing_man

Inspired by https://sleeplessbeastie.eu/2018/03/05/how-to-display-dependencies-for-deb-package/:

If you are stuck on a different system without access to dpkg/dpkg-deb, a quick hack is to use a combination of ar from binutils and tar to extract the necessary file/information. This can be installed via conda; e.g. for win-64:

conda install -c msys2 m2w64-binutils
conda install -c msys2 m2-tar

Example for extracting the control file information:

ar -x <input_file.deb> control.tar.gz
tar --to-stdout --gzip --extract --file control.tar.gz ./control

Example to extract license information (also see answer from Pandya)

ar -x gparted_0.18.0-1_i386.deb data.tar.bz2
tar --to-stdout --bzip2 --extract --file data.tar.bz2 ./usr/share/doc/gparted/copyright

If you are unsure about what’s in a .deb, you can use

ar -t <input_file.deb>

to list all files within the package file

Answered By: Oliver Zendel
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.