Interview Q&A / Linux & Shell

IntermediateQuick answer1 min readUpdated 3 Oct 2026

How do you find which package a file or command belongs to?

SHORT ANSWER

On Debian and Ubuntu use dpkg -S /path/to/file for installed files and apt-file search for files not yet installed. On Red Hat family systems use rpm -qf /path for installed files and dnf provides '*/name' for uninstalled ones.

Explain it simply

You see a command, or an error says a file is missing, and you want to know "which package gives me this?". It is like checking which shop a product came from.

Installed file, Debian/Ubuntu: dpkg -S /usr/bin/ssh prints openssh-client: /usr/bin/ssh. For a command name use dpkg -S $(which ssh). Careful: if /bin is a symlink to /usr/bin, query the real path (use readlink -f).

Not installed yet, Debian/Ubuntu: install apt-file, run sudo apt-file update, then apt-file search bin/dig. Result: dnsutils: /usr/bin/dig.

Red Hat family: rpm -qf /usr/bin/ssh for installed files; dnf provides '*/bin/dig' for any package in the repositories (output: bind-utils).

This is the standard answer to "command not found": many Ubuntu systems also print a suggestion from command-not-found. Knowing that dig lives in dnsutils or bind-utils saves a lot of searching.

Example

bash
dpkg -S /usr/bin/ssh
# openssh-client: /usr/bin/ssh
dnf provides '*/bin/dig'
# bind-utils-9.x ... : /usr/bin/dig

What to say in the interview

"For an installed file I use dpkg -S or rpm -qf. For a file in a package I have not installed, I use apt-file search or dnf provides. This is how I resolve a command not found error."

Common mistakes

  • Searching a symlinked path like /bin/ls and getting no result.

#linux#package-managers

Related questions

Practise more Linux & Shell questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Linux & Shell quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.