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

Gentoo

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.

Lynis Enterprise

Lynis Enterprise screenshot to help with system hardening

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

Does system hardening take a lot of time, or do you have any compliance in your company? Have a look at Lynis Enterprise.

Or start today with the open source security scanner Lynis (GitHub)


Leave a Reply

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