Tools for Debian Packages

Debian has been my primary Linux distribution of choice since 2003. That’s twenty years! How time flies! I haven’t ever worked as full-time server administrator but running and operating various kinds of systems have always been part of my skills, and it has made it possible for me to leverage wide range of tooling required in whatever job I’ve been handed.

In this post I’ll list some useful commands to query and maintain packages in Debian-based Linux distributions.

Listing all matching packages your system currently knows about:

dpkg -l zabbix\*

(-l = --list) It lists all the packages where the package name starts with “zabbix”. Example:

$ dpkg -l zabbix\*
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  zabbix-agent   1:5.0.29-1+debian10 amd64        Zabbix network monit(...)
ii  zabbix-release 1:5.0-1+buster      all          Zabbix official repo(...)
$

The asterisk in the argument requires escaping with a backslash. Alternatively the argument can be quoted: dpkg -l "zabbix*". If you don’t do that and you have a matching file in the current directory, the shell will expand the wildcard and you will have unexpected results.

The “ii” in the beginning of the line means that the package is currently installed.

Listing all the files contained in an installed package:

dpkg -L zabbix-release

(-L = --listfiles) Example:

$ dpkg -L zabbix-release
/.
/etc
/etc/apt
/etc/apt/sources.list.d
/etc/apt/sources.list.d/zabbix.list
/etc/apt/trusted.gpg.d
/etc/apt/trusted.gpg.d/zabbix-official-repo.gpg
/usr
/usr/share
/usr/share/doc
/usr/share/doc/zabbix-release
/usr/share/doc/zabbix-release/README.Debian
/usr/share/doc/zabbix-release/changelog.Debian
/usr/share/doc/zabbix-release/copyright
$

If you have a .deb file that is not yet installed and you want to see the list of files it contains:

dpkg -c filename.deb

(-c = --contents) Example:

$ ls zabbix*
zabbix-release_6.0-4+debian10_all.deb
$ dpkg -c zabbix-release_6.0-4+debian10_all.deb
drwxr-xr-x root/root      0 2022-09-14 10:44 ./
drwxr-xr-x root/root      0 2022-09-14 10:44 ./etc/
drwxr-xr-x root/root      0 2022-09-14 10:44 ./etc/apt/
drwxr-xr-x root/root      0 2022-09-14 10:44 ./etc/apt/sources.list.d/
-rwxr-xr-x root/root    172 2022-09-14 10:44 ./etc/apt/sources.list.d/zabbix-agent2-plugins.list
-rwxr-xr-x root/root    297 2022-09-14 10:44 ./etc/apt/sources.list.d/zabbix.list
drwxr-xr-x root/root      0 2022-09-14 10:44 ./etc/apt/trusted.gpg.d/
-rwxr-xr-x root/root   1183 2022-09-14 10:44 ./etc/apt/trusted.gpg.d/zabbix-official-repo.gpg
drwxr-xr-x root/root      0 2022-09-14 10:44 ./usr/
drwxr-xr-x root/root      0 2022-09-14 10:44 ./usr/share/
drwxr-xr-x root/root      0 2022-09-14 10:44 ./usr/share/doc/
drwxr-xr-x root/root      0 2022-09-14 10:44 ./usr/share/doc/zabbix-release/
-rw-r--r-- root/root    259 2022-06-09 10:58 ./usr/share/doc/zabbix-release/README.Debian
-rw-r--r-- root/root   4055 2022-09-14 10:44 ./usr/share/doc/zabbix-release/changelog.Debian
-rw-r--r-- root/root    551 2022-06-09 10:58 ./usr/share/doc/zabbix-release/copyright
$

If you want to know which package an existing file belongs to:

dpkg -S filename

(-S = --search) Example:

$ dpkg -S /usr/sbin/zabbix_agentd
zabbix-agent: /usr/sbin/zabbix_agentd
$

If you want to find out the yet uninstalled package that contains a specific file (to be able to install the correct package), you need to first install apt-file and update the database:

$ sudo apt install apt-file
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libapt-pkg-perl libexporter-tiny-perl liblist-moreutils-perl libregexp-assemble-perl
The following NEW packages will be installed:
  apt-file libapt-pkg-perl libexporter-tiny-perl liblist-moreutils-perl libregexp-assemble-perl
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 297 kB of archives.
After this operation, 825 kB of additional disk space will be used.
Do you want to continue? [Y/n]
...
Setting up libapt-pkg-perl (0.1.34+b1) ...
Setting up libexporter-tiny-perl (1.002001-1) ...
Setting up libregexp-assemble-perl (0.36-1) ...
Setting up liblist-moreutils-perl (0.416-1+b4) ...
Setting up apt-file (3.2.2) ...
The system-wide cache is empty. You may want to run 'apt-file update'
as root to update the cache.
Processing triggers for man-db (2.8.5-2) ...
$ sudo apt-file update
...
$

Then you can use apt-file search command to find the package that contains the specific file:

$ apt-file search bin/snmpwalk
snmp: /usr/bin/snmpwalk
$

Searching the package index for a package (installed or not installed):

apt-cache search zabbix

It searches the full package list (as retrieved previously by “apt update” command) for the word (regular expression). Example:

$ apt-cache search zabbix
nagstamon - Nagios status monitor which takes place in systray or on desktop
pcp-export-zabbix-agent - Module for exporting PCP metrics to Zabbix agent
python3-protobix - Implementation of Zabbix Sender protocol (Python 3)
python3-pyzabbix - Zabbix API Python interface.
resource-agents - Cluster Resource Agents
uwsgi-core - fast, self-healing application container server (core)
zabbix-agent - network monitoring solution - agent
zabbix-frontend-php - network monitoring solution - PHP front-end
zabbix-java-gateway - network monitoring solution - Java gateway
zabbix-proxy-mysql - network monitoring solution - proxy (using MySQL)
zabbix-proxy-pgsql - network monitoring solution - proxy (using PostgreSQL)
zabbix-proxy-sqlite3 - network monitoring solution - proxy (using SQLite3)
zabbix-server-mysql - network monitoring solution - server (using MySQL)
zabbix-server-pgsql - network monitoring solution - server (using PostgreSQL)
$

You can also use “apt-cache show packagename” command to get more information about the listed packages.

If you are interested in more information about administering Debian-based installations, see The Debian Administrator’s Handbook.

Updated: November 24, 2023 — 22:13

Leave a Reply