Linux Survival Basics
Read-onlyFind Broken or Leftover dpkg States
A host has package trouble and you need to spot half-configured packages or removed packages with leftover config.
Command
dpkg-query -W -f='${db:Status-Abbrev}\t${Package}\n' | awk '$1 !~ /^ii$/'
Before you run this
System impact: Read-only. Low when scoped to the shown target.
When not to use it: Do not delete packages based only on this output; inspect each state and package purpose first.
Expected output
Rows such as iF app-agent or rc old-kernel-tools that need review.
System impact
Read-only. Nothing changes. The command filters dpkg status abbreviations to rows that are not clean ii installed packages.
Recovery / rollback: no state is changed.
When to use it
Use after interrupted installs, failed upgrades, or package repair sessions.
When not to use it
Do not delete packages based only on this output; inspect each state and package purpose first.
Watch this command run
Command transcript
This sanitized transcript shows the commands and output shape without exposing host details.
$ dpkg-query -W -f='${db:Status-Abbrev}\t${Package}\n'
ii base-files
ii bash
ii curl
ii libc6
ii linux-image-6.8.0-60-generic
ii nginx
ii openssl
ii python3
ii zlib1g
iF app-agent
rc old-kernel-tools
$ dpkg-query -W -f='${db:Status-Abbrev}\t${Package}\n' | awk '$1 !~ /^ii$/'
iF app-agent
rc old-kernel-tools
View commands shown
These are the commands shown in the sanitized transcript.
Commands shown
dpkg-query -W -f='${db:Status-Abbrev}\t${Package}\n'dpkg-query -W -f='${db:Status-Abbrev}\t${Package}\n' | awk '$1 !~ /^ii$/'
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"'
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
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 Which Package Owns a File
That binary came from somewhere. dpkg can tell you where.
dpkg-query -S /usr/sbin/nginx
Check One Installed Package Cleanly
For one package, dpkg-query gives a clean status line.
dpkg-query -W -f='${Status} ${Version}\n' openssl
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.