Discover to which package a file belongs to

Determine the package a file belongs do

Sometimes you want to know the related package of a file, before installation, or when it is already there. This is of great help during system hardening or general system cleanups. In this article we have a look at several ways to determine the relationships between files and the package they belong to.

CentOS, Fedora, RHEL

Show files per installed package

To show what files are in a package, use the rpm command.

rpm -ql package

Debian and Ubuntu

Discover related package

If you want to find the related package of a binary (or file), we first have to know the full path. If you know the binary, then use the which command to discover where it is stored. Using the find command is another option, but may be less efficient. With the dpkg package management tool we can find the related package.

dpkg -S /usr/sbin/atd | awk -F: ‘{print $1}’

Without the awk command, the output will look like this.

Determine file and its related-package on Debian and Ubuntu

Show files installed by package

If you already know the package name, you can quickly look up the files that are installed by a Debian package.

dpkg -L package

With the earlier discovered at package we see what it exactly installs and where.

Show files installed by a Debian package


The first option is using equery, which is part of the package app-portage/gentoolkit.

equery files <installed package>

The package itself should be installed.

Next alternative is qlist, which is part of app-portage/portage-utils

qlist <installed package>

Got more useful commands to share? Let it know in the comments and we add them to the article.

Automate security audits and know your risks
Lynis Enterprise screenshot to help with system hardening

This blog post is part of our Linux security series to get Linux and Unix-based systems more secure.

Is system hardening taking a lot of time for you? Don't know where to start? We solved that problem: Lynis Enterprise.


Leave a Reply

Your email address will not be published. Required fields are marked *