Linux Survival Basics
Read-onlyCheck One Installed Package Cleanly
You need to confirm whether one package is installed and capture its exact installed version without noisy apt output.
Command
dpkg-query -W -f='${Status} ${Version}\n' openssl
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 find the newest available version; use apt policy for candidate information.
Expected output
A status and version line such as install ok installed 3.0.13-0ubuntu3.5.
System impact
Read-only. Nothing changes. dpkg-query reads the local dpkg database for one package.
Recovery / rollback: no state is changed.
When to use it
Use in runbooks, support tickets, and package audits where one exact installed version matters.
When not to use it
Do not use it to find the newest available version; use apt policy for candidate information.
Watch this command run
Command transcript
This sanitized transcript shows the commands and output shape without exposing host details.
$ dpkg-query -W -f='${Status} ${Version}\n' openssl
install ok installed 3.0.13-0ubuntu3.5
$ dpkg-query -W -f='${Status} ${Version}\n' nginx
install ok installed 1.24.0-2ubuntu7.3
View commands shown
These are the commands shown in the sanitized transcript.
Commands shown
dpkg-query -W -f='${Status} ${Version}\n' openssldpkg-query -W -f='${Status} ${Version}\n' nginx
next steps
Related commands
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"'
List Installed Package Versions
A package inventory beats memory when a server is drifting.
dpkg-query -W -f='${Package}\t${Version}\t${Architecture}\n' | sort
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$/'
Find Which Package Owns a File
That binary came from somewhere. dpkg can tell you where.
dpkg-query -S /usr/sbin/nginx
Fingerprint a Debian or Ubuntu Host
Before package triage, prove what OS family and release you are actually on.
. /etc/os-release && printf '%s %s %s\n' "$ID" "$VERSION_ID" "$VERSION_CODENAME"
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.
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.