dpkg-deb
Package and unpack Debian (.deb) archives
TLDR
Display information about a package
Display the package's name and version on one line
List the package's contents
Extract package's contents into a directory
Create a package from a specified directory
SYNOPSIS
dpkg-deb command [options]
Common commands:
dpkg-deb --build directory [archive | directory]
dpkg-deb --extract archive directory
dpkg-deb --info archive [control-field...]
dpkg-deb --contents archive
dpkg-deb --control archive [directory]
PARAMETERS
--build directory [archive | directory]
Builds a Debian package archive from the given directory. The archive argument specifies the output file, or if a directory is given, the package will be placed in that directory with a generated filename.
--extract archive directory (or -x)
Extracts all files from archive into the specified directory, preserving ownership and permissions.
--x-extract archive directory
Similar to --extract, but does not preserve file ownership or permissions (i.e., it doesn't chown or chmod extracted files).
--info archive [control-field...] (or -I)
Displays information from the control file of archive (e.g., Package, Version, Description). Specific control fields can be requested.
--contents archive (or -c)
Lists the files contained within the archive and their permissions, ownership, and size.
--control archive [directory] (or -e)
Extracts the control files (e.g., control, preinst, postinst) from the archive into the specified directory (defaults to the current directory).
--fsys-tarfile archive (or -f)
Extracts the filesystem tarfile portion of the archive to standard output. This is the tarball containing the package's actual data.
--conffiles archive
Lists the conffiles (configuration files) from the archive that are managed by dpkg.
--deb-version archive
Prints the Debian package version string from the archive to standard output.
--show archive (or -S)
Displays single-line information about the package: its name, version, and architecture.
--showformat format (or -s)
Sets the output format for the --show command. Uses a printf-like syntax with various item fields.
-zlevel
Specify the compression level (0-9) for the data and control tarfiles when building new packages with --build.
-Ztype
Specify the compression type for the data and control tarfiles when building new packages with --build (e.g., gzip, xz, zstd, lzma, none).
--debug
Enables debugging output, providing more verbose information about dpkg-deb's operations.
--root-owner-group
When extracting files, set the owner and group of extracted files to root. This overrides the original ownership in the archive.
--no-ownership
When extracting files, do not preserve the original owner of extracted files, setting them to the user running the command instead.
--no-permissions
When extracting files, do not preserve the original permissions of extracted files, setting them to the user's umask.
DESCRIPTION
dpkg-deb is a low-level tool used to manipulate Debian package archives (.deb files). It can build new packages from a package directory, extract files from an existing package, list its contents, or display control information. It acts as an interface to the underlying ar and tar commands, which actually perform the archiving and compression. While dpkg is the primary tool for installing, removing, and managing packages, dpkg-deb is crucial for developers and those needing to inspect or create .deb files directly, offering fine-grained control over the package structure and contents.
CAVEATS
dpkg-deb is a low-level utility and does not handle package dependencies or interact with the installed package database. It simply processes the .deb archive file itself. Using it to extract or modify packages requires a good understanding of the Debian package format, and incorrect manipulation can lead to corrupted packages or system instability if not handled carefully. It is typically used by package maintainers or for advanced debugging, not for general package installation or removal.
DEBIAN PACKAGE FORMAT
A Debian binary package (.deb file) is essentially an ar archive containing three required members:
1. A debian-binary file: Contains the version number of the Debian binary package format.
2. A control.tar archive (can be compressed, e.g., control.tar.xz): Contains control information about the package, such as metadata (name, version, dependencies) and maintainer scripts (preinst, postinst, prerm, postrm).
3. A data.tar archive (can be compressed, e.g., data.tar.gz): Contains the actual filesystem hierarchy that the package installs.
COMPRESSION SUPPORT
dpkg-deb supports various compression methods for the control and data tarballs within a .deb archive. When building packages, the compression type can be specified using the -Z option (e.g., gzip, xz, zstd, lzma, none), and the compression level using the -z option. This flexibility allows package maintainers to balance package size and decompression speed.
HISTORY
dpkg-deb is a fundamental component of the Debian packaging system, dating back to its early days. It was designed as a core utility to implement the low-level operations for creating and inspecting .deb files, which serve as the standard package format for Debian and its derivatives like Ubuntu. Its development has closely mirrored the evolution of the Debian project, ensuring strict adherence to the evolving .deb format specification and supporting new compression methods and package features as they were introduced.