Linux Survival Basics
Read-onlyFind Which Package Owns a File
You see a file or command on a Debian or Ubuntu host and need to identify the package that installed it.
Command
dpkg-query -S /usr/sbin/nginx
Before you run this
System impact: Read-only. Low when scoped to the shown target.
When not to use it: Do not expect it to identify files copied manually outside the package database.
Expected output
A package-to-path mapping such as nginx: /usr/sbin/nginx.
System impact
Read-only. Nothing changes. dpkg-query searches the local package ownership database.
Recovery / rollback: no state is changed.
When to use it
Use when auditing binaries, tracing config files, or deciding which package documentation to read.
When not to use it
Do not expect it to identify files copied manually outside the package database.
Watch this command run
Command transcript
This sanitized transcript shows the commands and output shape without exposing host details.
$ dpkg-query -S /usr/sbin/nginx
nginx: /usr/sbin/nginx
$ dpkg-query -S /usr/bin/curl
curl: /usr/bin/curl
View commands shown
These are the commands shown in the sanitized transcript.
Commands shown
dpkg-query -S /usr/sbin/nginxdpkg-query -S /usr/bin/curl
next steps
Related commands
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
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$/'
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"'
Check the Installed and Candidate Package Version
apt policy explains where the next version would come from.
apt policy nginx
Find the Exact Log Line Before You Scroll
The error was there. The useful part was knowing exactly where it was.
grep -inE 'error|failed|denied|timeout' /var/log/nginx/error.log
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.