Back to commands

Linux Survival Basics

Read-only

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

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.

demo@lab:~$

$ 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

  1. dpkg-query -S /usr/sbin/nginx
  2. dpkg-query -S /usr/bin/curl

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

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$/'
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 Can be slow

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.

  • lpic1:102-package-management
  • lpic1:103-gnu-unix-commands
  • lfcs:essential-commands
  • lfcs:operations-deployment
  • 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.