Back to commands

Linux Survival Basics

Read-only

List Installed Package Versions

You need a deterministic list of installed Debian packages, versions, and architectures for comparison or incident notes.

Command

dpkg-query -W -f='${Package}\t${Version}\t${Architecture}\n' | sort

Before you run this

System impact: Read-only. Low when scoped to the shown target.

When not to use it: Do not use it to discover available updates; use apt list --upgradable for candidate upgrades.

Expected output

Sorted package, version, and architecture rows.

System impact

Read-only. Nothing changes. dpkg-query reads the local package database and prints a sorted inventory.

Recovery / rollback: no state is changed.

When to use it

Use before upgrades, after incidents, during fleet comparison, or when handing a host to another operator.

When not to use it

Do not use it to discover available updates; use apt list --upgradable for candidate upgrades.

Watch this command run

Command transcript

This sanitized transcript shows the commands and output shape without exposing host details.

demo@lab:~$

$ dpkg-query -W | head

base-files	13ubuntu10.2	amd64
bash	5.2.21-2ubuntu4	amd64
curl	8.5.0-2ubuntu10.6	amd64
libc6	2.39-0ubuntu8.4	amd64
linux-image-6.8.0-60-generic	6.8.0-60.63	amd64
nginx	1.24.0-2ubuntu7.3	amd64
openssl	3.0.13-0ubuntu3.5	amd64
python3	3.12.3-0ubuntu2	amd64
zlib1g	1:1.3.dfsg-3.1ubuntu2	amd64
zlib1g:i386	1:1.3.dfsg-3.1ubuntu2	i386

$ dpkg-query -W -f='${Package}\t${Version}\t${Architecture}\n' | sort

base-files	13ubuntu10.2	amd64
bash	5.2.21-2ubuntu4	amd64
curl	8.5.0-2ubuntu10.6	amd64
libc6	2.39-0ubuntu8.4	amd64
linux-image-6.8.0-60-generic	6.8.0-60.63	amd64
nginx	1.24.0-2ubuntu7.3	amd64
openssl	3.0.13-0ubuntu3.5	amd64
python3	3.12.3-0ubuntu2	amd64
zlib1g	1:1.3.dfsg-3.1ubuntu2	amd64
zlib1g:i386	1:1.3.dfsg-3.1ubuntu2	i386
View commands shown

These are the commands shown in the sanitized transcript.

Commands shown

  1. dpkg-query -W | head
  2. dpkg-query -W -f='${Package}\t${Version}\t${Architecture}\n' | sort

next steps

Related commands

Linux Survival Basics Read-only

Find the Largest Installed Packages

Disk cleanup starts with evidence, not random package removal.

dpkg-query -W -f='${Installed-Size}\t${Package}\n' | sort -nr | head -20
Linux Survival Basics Read-only

Spot Foreign-Architecture Packages

One unexpected architecture can explain confusing dependency output.

dpkg-query -W -f='${Architecture}\t${Package}\n' | awk '$1 != "amd64" && $1 != "all"'
Linux Survival Basics Read-only

Find Broken or Leftover dpkg States

Not every package row is cleanly installed.

dpkg-query -W -f='${db:Status-Abbrev}\t${Package}\n' | awk '$1 !~ /^ii$/'
Study mapping

Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.

  • lpic1:102-package-management
  • lpic1:103-gnu-unix-commands
  • lfcs:essential-commands
  • lfcs:operations-deployment
  • linuxplus:automation-scripting
  • linuxplus:provisional
  • linuxplus:system-management
  • risk:read-only

Useful for

  • LPIC-1 style command-line practice
  • LFCS style performance tasks
  • Linux+ style troubleshooting review

Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.