CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Packages & Services / dpkg

dpkg

Query and install .deb packages directly

Intermediatepackagesubuntuforensics

dpkg is the low-level Debian package tool that apt drives. It installs or removes individual .deb files without fetching dependencies, and it's the fastest way to ask the local database what's installed, which package owns a file and what a package put on disk.

Syntaxdpkg {-l|-L|-S|-s|-i|-r|-P|-V|--configure} [OPTIONS] [PACKAGE | FILE.deb | PATTERN]...

Watch it run

You're auditing an Ubuntu server: list packages, then trace a binary and a config file back to their packages.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 4
dpkg -l | head -8

The header decodes the first two letters of each row: what you asked for (desired) and the actual state. ii means 'install wanted, installed OK'.

Anatomy of a command

$
commanddpkg

The Debian package manager. Database in /var/lib/dpkg (status file + info/*.list).

How it works

A .deb is an ar archive with three members: debian-binary, control.tar (metadata: name, version, Depends, maintainer scripts preinst/postinst/prerm/postrm, md5sums and conffiles) and data.tar (the files). dpkg -i unpacks in two phases: unpack runs preinst and extracts data.tar to the filesystem, then configure runs postinst. Between them the package is 'unpacked' but not configured, which is the state you see after a dependency failure (iU in dpkg -l). The database is plain text: /var/lib/dpkg/status holds every package's state and metadata, and /var/lib/dpkg/info/<pkg>.list lists every file it owns, which is what -L and -S read. dpkg checks dependencies but never downloads anything; apt does that. Conffiles under /etc are tracked by checksum, so an upgrade asks before replacing one you edited. A lock on /var/lib/dpkg/lock stops two dpkg runs at once.

Options you'll actually use

-l [PATTERN]List packages with their state (ii, rc, iU...)
-L PKGList files installed by a package
-S PATH|PATTERNFind the package that owns a file
-s PKGStatus and metadata of an installed package
-i FILE.debInstall (unpack + configure) a package file
-r / -P PKGRemove (keep config) / purge (delete config too)
-I / -c FILE.debShow a .deb's control info / list its contents
-V [PKG]Verify installed files against stored md5sums
--configure -aFinish configuring every unpacked package (after an interrupted install)
--get-selectionsDump package selections (install/hold/deinstall)
dpkg-query -W -f=FMTScript-friendly custom output

Common mistakes

sudo dpkg -i app.deb and walking away

dpkg doesn't fetch dependencies, so the package can be left unpacked and unconfigured (iU), blocking apt.

sudo apt install ./app.deb
dpkg -l | grep nginx to check whether nginx is installed

rc (removed, config left) and un rows also match, so a removed package looks installed.

dpkg-query -W -f='${Status}\n' nginx # 'install ok installed' or not
Editing /var/lib/dpkg/status by hand to 'fix' a broken package

One wrong field corrupts the database for every package.

sudo dpkg --configure -a; sudo apt -f install
dpkg -r to remove a package with dependents

dpkg refuses with 'dependency problems - not removing', and --force-depends leaves the system broken.

sudo apt remove <pkg> # shows and removes dependents explicitly

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Find which package installed /usr/bin/ss and list every file in that package that lives under /usr/bin or /usr/sbin.

  2. 2

    Show the installed version of bash using a script-friendly format: just the version string.

  3. 3

    List the five largest installed packages by installed size.

  4. 4

    Check whether any files from the coreutils package were modified or deleted.

Related commands

aptInstall, upgrade and remove packages on Debian and UbunturpmQuery, verify and install RPM packages directlyfindSearch the filesystem by name, size, age, owner and more
PreviousrpmNextsystemctl
Linux / Packages & Services / dpkg

dpkg

Query and install .deb packages directly

Intermediatepackagesubuntuforensics

dpkg is the low-level Debian package tool that apt drives. It installs or removes individual .deb files without fetching dependencies, and it's the fastest way to ask the local database what's installed, which package owns a file and what a package put on disk.

Syntaxdpkg {-l|-L|-S|-s|-i|-r|-P|-V|--configure} [OPTIONS] [PACKAGE | FILE.deb | PATTERN]...

Watch it run

You're auditing an Ubuntu server: list packages, then trace a binary and a config file back to their packages.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 4
dpkg -l | head -8

The header decodes the first two letters of each row: what you asked for (desired) and the actual state. ii means 'install wanted, installed OK'.

Anatomy of a command

$
commanddpkg

The Debian package manager. Database in /var/lib/dpkg (status file + info/*.list).

How it works

A .deb is an ar archive with three members: debian-binary, control.tar (metadata: name, version, Depends, maintainer scripts preinst/postinst/prerm/postrm, md5sums and conffiles) and data.tar (the files). dpkg -i unpacks in two phases: unpack runs preinst and extracts data.tar to the filesystem, then configure runs postinst. Between them the package is 'unpacked' but not configured, which is the state you see after a dependency failure (iU in dpkg -l). The database is plain text: /var/lib/dpkg/status holds every package's state and metadata, and /var/lib/dpkg/info/<pkg>.list lists every file it owns, which is what -L and -S read. dpkg checks dependencies but never downloads anything; apt does that. Conffiles under /etc are tracked by checksum, so an upgrade asks before replacing one you edited. A lock on /var/lib/dpkg/lock stops two dpkg runs at once.

Options you'll actually use

-l [PATTERN]List packages with their state (ii, rc, iU...)
-L PKGList files installed by a package
-S PATH|PATTERNFind the package that owns a file
-s PKGStatus and metadata of an installed package
-i FILE.debInstall (unpack + configure) a package file
-r / -P PKGRemove (keep config) / purge (delete config too)
-I / -c FILE.debShow a .deb's control info / list its contents
-V [PKG]Verify installed files against stored md5sums
--configure -aFinish configuring every unpacked package (after an interrupted install)
--get-selectionsDump package selections (install/hold/deinstall)
dpkg-query -W -f=FMTScript-friendly custom output

Common mistakes

sudo dpkg -i app.deb and walking away

dpkg doesn't fetch dependencies, so the package can be left unpacked and unconfigured (iU), blocking apt.

sudo apt install ./app.deb
dpkg -l | grep nginx to check whether nginx is installed

rc (removed, config left) and un rows also match, so a removed package looks installed.

dpkg-query -W -f='${Status}\n' nginx # 'install ok installed' or not
Editing /var/lib/dpkg/status by hand to 'fix' a broken package

One wrong field corrupts the database for every package.

sudo dpkg --configure -a; sudo apt -f install
dpkg -r to remove a package with dependents

dpkg refuses with 'dependency problems - not removing', and --force-depends leaves the system broken.

sudo apt remove <pkg> # shows and removes dependents explicitly

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Find which package installed /usr/bin/ss and list every file in that package that lives under /usr/bin or /usr/sbin.

  2. 2

    Show the installed version of bash using a script-friendly format: just the version string.

  3. 3

    List the five largest installed packages by installed size.

  4. 4

    Check whether any files from the coreutils package were modified or deleted.

Related commands

aptInstall, upgrade and remove packages on Debian and UbunturpmQuery, verify and install RPM packages directlyfindSearch the filesystem by name, size, age, owner and more
PreviousrpmNextsystemctl