< Previous | Contents | Next >
Querying dpkg’s Database and Inspecting .deb Files
We will begin with several dpkg options that query the internal dpkg database. This database resides on the filesystem at /var/lib/dpkg and contains multiple sections including configura- tion scripts (/var/lib/dpkg/info), a list of files the package installed (/var/lib/dpkg/info/*. list), and the status of each package that has been installed (/var/lib/dpkg/status). You can use dpkg to interact with the files in this database. Note that most options are available in a long
version (one or more relevant words, preceded by a double dash) and a short version (a single letter, often the initial of one word from the long version, and preceded by a single dash). This convention is so common that it is a POSIX standard.
First, let’s take a look at --listfiles package (or -L), which lists the files that were installed by the specified package:
$ dpkg -L base-passwd
/.
/usr
/usr/sbin
/usr/sbin/update-passwd
/usr/share
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/base-passwd
/usr/share/doc-base
/usr/share/doc-base/users-and-groups
/usr/share/base-passwd
/usr/share/base-passwd/group.master
/usr/share/base-passwd/passwd.master
/usr/share/man
/usr/share/man/pl
/usr/share/man/pl/man8
/usr/share/man/pl/man8/update-passwd.8.gz [...]
/usr/share/doc
/usr/share/doc/base-passwd
/usr/share/doc/base-passwd/users-and-groups.txt.gz
/usr/share/doc/base-passwd/changelog.gz
/usr/share/doc/base-passwd/copyright
/usr/share/doc/base-passwd/README
/usr/share/doc/base-passwd/users-and-groups.html
$ dpkg -L base-passwd
/.
/usr
/usr/sbin
/usr/sbin/update-passwd
/usr/share
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/base-passwd
/usr/share/doc-base
/usr/share/doc-base/users-and-groups
/usr/share/base-passwd
/usr/share/base-passwd/group.master
/usr/share/base-passwd/passwd.master
/usr/share/man
/usr/share/man/pl
/usr/share/man/pl/man8
/usr/share/man/pl/man8/update-passwd.8.gz [...]
/usr/share/doc
/usr/share/doc/base-passwd
/usr/share/doc/base-passwd/users-and-groups.txt.gz
/usr/share/doc/base-passwd/changelog.gz
/usr/share/doc/base-passwd/copyright
/usr/share/doc/base-passwd/README
/usr/share/doc/base-passwd/users-and-groups.html
Next, dpkg --search file (or -S), finds any packages containing the file or path passed in the argument. For example, to find the package containing /bin/date:
$ dpkg -S /bin/date
coreutils: /bin/date
$ dpkg -S /bin/date
coreutils: /bin/date
The dpkg --status package (or -s) command displays the headers of an installed package. For example, to search the headers for the coreutils package:
$ dpkg -s coreutils Package: coreutils Essential: yes
Status: install ok installed
$ dpkg -s coreutils Package: coreutils Essential: yes
Status: install ok installed
Priority: required Section: utils Installed-Size: 13855
Maintainer: Michael Stone <mstone@debian.org> Architecture: amd64
Multi-Arch: foreign Version: 8.23-3
Replaces: mktemp, realpath, timeout
Pre-Depends: libacl1 (>= 2.2.51-8), libattr1 (>= 1:2.4.46-8), libc6 (>= 2.17),
➥ libselinux1 (>= 2.1.13) Conflicts: timeout
Description: GNU core utilities
This package contains the basic file, shell and text manipulation utilities which are expected to exist on every operating system.
.
Specifically, this package includes:
arch base64 basename cat chcon chgrp chmod chown chroot cksum comm cp csplit cut date dd df dir dircolors dirname du echo env expand expr factor false flock fmt fold groups head hostid id install join link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup nproc numfmt od paste pathchk pinky pr printenv printf ptx pwd readlink realpath rm rmdir runcon sha*sum seq shred sleep sort split stat stty sum sync tac tail tee test timeout touch tr true truncate tsort tty uname unexpand uniq unlink users vdir wc who whoami yes
Homepage: http://gnu.org/software/coreutils
Priority: required Section: utils Installed-Size: 13855
Maintainer: Michael Stone <mstone@debian.org> Architecture: amd64
Multi-Arch: foreign Version: 8.23-3
Replaces: mktemp, realpath, timeout
Pre-Depends: libacl1 (>= 2.2.51-8), libattr1 (>= 1:2.4.46-8), libc6 (>= 2.17),
➥ libselinux1 (>= 2.1.13) Conflicts: timeout
Description: GNU core utilities
This package contains the basic file, shell and text manipulation utilities which are expected to exist on every operating system.
.
Specifically, this package includes:
arch base64 basename cat chcon chgrp chmod chown chroot cksum comm cp csplit cut date dd df dir dircolors dirname du echo env expand expr factor false flock fmt fold groups head hostid id install join link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup nproc numfmt od paste pathchk pinky pr printenv printf ptx pwd readlink realpath rm rmdir runcon sha*sum seq shred sleep sort split stat stty sum sync tac tail tee test timeout touch tr true truncate tsort tty uname unexpand uniq unlink users vdir wc who whoami yes
Homepage: http://gnu.org/software/coreutils
amd64
amd64
backdoor-facto 3.4.2-0kali1 all
backupninja backuppc baobab
backdoor-facto 3.4.2-0kali1 all
backupninja backuppc baobab
<none>
<none> 3.22.1-1
<none>
<none> 3.22.1-1
<none>
<none> amd64
<none>
<none> amd64
The dpkg --list (or -l) command displays the list of packages known to the system and their installation status. You can also use grep on the output to search for certain fields, or provide wildcards (such as b*) to search for packages that match a particular partial search string. This will show a summary of the packages. For example, to show a summary list of all packages that start with ’b’:
$ dpkg -l ’b*’
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
$ dpkg -l ’b*’
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii
ii un un ii
b43-fwcutter
1:019-3
utility for extracting Broadcom 4
Patch win32/64 binaries with shel (no description available)
(no description available)
GNOME disk usage analyzer
ii
ii un un ii
[...]
[...]
The dpkg --contents file.deb (or -c) command lists all the files in a particular .deb file:
$ dpkg -c /var/cache/apt/archives/gnupg_1.4.18-6_amd64.deb
drwxr-xr-x root/root 0 2014-12-04 23:03 ./
drwxr-xr-x root/root 0 2014-12-04 23:03 ./lib/
drwxr-xr-x root/root 0 2014-12-04 23:03 ./lib/udev/
drwxr-xr-x root/root 0 2014-12-04 23:03 ./lib/udev/rules.d/
-rw-r--r-- root/root 2711 2014-12-04 23:03 ./lib/udev/rules.d/60-gnupg.rules
drwxr-xr-x root/root 0 2014-12-04 23:03 ./usr/
drwxr-xr-x root/root 0 2014-12-04 23:03 ./usr/lib/
drwxr-xr-x root/root 0 2014-12-04 23:03 ./usr/lib/gnupg/
-rwxr-xr-x root/root 39328 2014-12-04 23:03 ./usr/lib/gnupg/gpgkeys_ldap
-rwxr-xr-x root/root 92872 2014-12-04 23:03 ./usr/lib/gnupg/gpgkeys_hkp
-rwxr-xr-x root/root 47576 2014-12-04 23:03 ./usr/lib/gnupg/gpgkeys_finger
-rwxr-xr-x root/root 84648 2014-12-04 23:03 ./usr/lib/gnupg/gpgkeys_curl
-rwxr-xr-x root/root 3499 2014-12-04 23:03 ./usr/lib/gnupg/gpgkeys_mailto
drwxr-xr-x root/root 0 2014-12-04 23:03 ./usr/bin/
-rwxr-xr-x root/root 60128 2014-12-04 23:03 ./usr/bin/gpgsplit
-rwxr-xr-x root/root 1012688 2014-12-04 23:03 ./usr/bin/gpg [...]
$ dpkg -c /var/cache/apt/archives/gnupg_1.4.18-6_amd64.deb
drwxr-xr-x root/root 0 2014-12-04 23:03 ./
drwxr-xr-x root/root 0 2014-12-04 23:03 ./lib/
drwxr-xr-x root/root 0 2014-12-04 23:03 ./lib/udev/
drwxr-xr-x root/root 0 2014-12-04 23:03 ./lib/udev/rules.d/
-rw-r--r-- root/root 2711 2014-12-04 23:03 ./lib/udev/rules.d/60-gnupg.rules
drwxr-xr-x root/root 0 2014-12-04 23:03 ./usr/
drwxr-xr-x root/root 0 2014-12-04 23:03 ./usr/lib/
drwxr-xr-x root/root 0 2014-12-04 23:03 ./usr/lib/gnupg/
-rwxr-xr-x root/root 39328 2014-12-04 23:03 ./usr/lib/gnupg/gpgkeys_ldap
-rwxr-xr-x root/root 92872 2014-12-04 23:03 ./usr/lib/gnupg/gpgkeys_hkp
-rwxr-xr-x root/root 47576 2014-12-04 23:03 ./usr/lib/gnupg/gpgkeys_finger
-rwxr-xr-x root/root 84648 2014-12-04 23:03 ./usr/lib/gnupg/gpgkeys_curl
-rwxr-xr-x root/root 3499 2014-12-04 23:03 ./usr/lib/gnupg/gpgkeys_mailto
drwxr-xr-x root/root 0 2014-12-04 23:03 ./usr/bin/
-rwxr-xr-x root/root 60128 2014-12-04 23:03 ./usr/bin/gpgsplit
-rwxr-xr-x root/root 1012688 2014-12-04 23:03 ./usr/bin/gpg [...]
The dpkg --info file.deb (or -I) command displays the headers of the specified .deb file:
$ dpkg -I /var/cache/apt/archives/gnupg_1.4.18-6_amd64.deb
new debian package, version 2.0.
size 1148362 bytes: control archive=3422 bytes.
$ dpkg -I /var/cache/apt/archives/gnupg_1.4.18-6_amd64.deb
new debian package, version 2.0.
size 1148362 bytes: control archive=3422 bytes.
1264 bytes,
4521 bytes,
479 bytes,
473 bytes, Package: gnupg Version: 1.4.18-6
26 lines
65 lines
13 lines
13 lines
control
md5sums
* postinst
* preinst
#!/bin/sh
#!/bin/sh
1264 bytes,
4521 bytes,
479 bytes,
473 bytes, Package: gnupg Version: 1.4.18-6
Architecture: amd64
Maintainer: Debian GnuPG-Maintainers <pkg-gnupg-maint@lists.alioth.debian.org> Installed-Size: 4888
Depends: gpgv, libbz2-1.0, libc6 (>= 2.15), libreadline6 (>= 6.0), libusb-0.1-4 (>=
➥ 2:0.1.12), zlib1g (>= 1:1.1.4)
Recommends: gnupg-curl, libldap-2.4-2 (>= 2.4.7)
Suggests: gnupg-doc, libpcsclite1, parcimonie, xloadimage | imagemagick | eog Section: utils
Priority: important Multi-Arch: foreign
Homepage: http://www.gnupg.org
Description: GNU privacy guard - a free PGP replacement
GnuPG is GNU’s tool for secure communication and data storage. It can be used to encrypt data and to create digital signatures. It includes an advanced key management facility and is compliant
Architecture: amd64
Maintainer: Debian GnuPG-Maintainers <pkg-gnupg-maint@lists.alioth.debian.org> Installed-Size: 4888
Depends: gpgv, libbz2-1.0, libc6 (>= 2.15), libreadline6 (>= 6.0), libusb-0.1-4 (>=
➥ 2:0.1.12), zlib1g (>= 1:1.1.4)
Recommends: gnupg-curl, libldap-2.4-2 (>= 2.4.7)
Suggests: gnupg-doc, libpcsclite1, parcimonie, xloadimage | imagemagick | eog Section: utils
Priority: important Multi-Arch: foreign
Homepage: http://www.gnupg.org
Description: GNU privacy guard - a free PGP replacement
GnuPG is GNU’s tool for secure communication and data storage. It can be used to encrypt data and to create digital signatures. It includes an advanced key management facility and is compliant
with the proposed OpenPGP Internet standard as described in RFC 4880. [...]
with the proposed OpenPGP Internet standard as described in RFC 4880. [...]
You can also use dpkg to compare package version numbers with the --compare-versions option, which is often called by external programs, including configuration scripts executed by dpkg itself. This option requires three parameters: a version number, a comparison operator, and a second version number. The different possible operators are: lt (strictly less than), le (less than or equal to), eq (equal), ne (not equal), ge (greater than or equal to), and gt (strictly greater than). If the comparison is correct, dpkg returns 0 (success); if not, it gives a non-zero return value (indicating failure). Consider these comparisons:
$ dpkg --compare-versions 1.2-3 gt 1.1-4
$ echo $?
0
$ dpkg --compare-versions 1.2-3 lt 1.1-4
$ echo $?
1
$ dpkg --compare-versions 2.6.0pre3-1 lt 2.6.0-1
$ echo $?
1
$ dpkg --compare-versions 1.2-3 gt 1.1-4
$ echo $?
0
$ dpkg --compare-versions 1.2-3 lt 1.1-4
$ echo $?
1
$ dpkg --compare-versions 2.6.0pre3-1 lt 2.6.0-1
$ echo $?
1
Note the unexpected failure of the last comparison: for dpkg, the string ”pre” (usually denoting a pre-release) has no particular meaning, and dpkg simply interprets it as a string, in which case ”2. 6.0pre3-1” is alphabetically greater than ”2.6.0-1”. When we want a package’s version number to indicate that it is a pre-release, we use the tilde character, “~”:
$ dpkg --compare-versions 2.6.0~pre3-1 lt 2.6.0-1
$ echo $?
0
$ dpkg --compare-versions 2.6.0~pre3-1 lt 2.6.0-1
$ echo $?
0