Linux Survival Basics
Find 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
What changed
Nothing changes. dpkg-query searches the local package ownership database.
Danger
safe
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.
Undo or recovery
No undo needed because the command is read-only.
Expected output
A package-to-path mapping such as nginx: /usr/sbin/nginx.
demo script
Disposable terminal steps
dpkg-query -S /usr/sbin/nginxdpkg-query -S /usr/bin/curl
simulated output
What it looks like
::fixture-ready::
$ dpkg-query -S /usr/sbin/nginx
nginx: /usr/sbin/nginx
::exit-code::0
$ dpkg-query -S /usr/bin/curl
curl: /usr/bin/curl
::exit-code::0
YouTube Short
Find a file's package.
If you find a binary on a Debian system, ask dpkg which package owns that path before guessing.
LinkedIn hook
That binary came from somewhere. dpkg can tell you where.
Question: Do you trace unfamiliar binaries back to package ownership?
experiments
A/B tests to run
Metric: save_rate
A: Which package owns this file?
B: Trace binaries before touching them.