Monday, September 07, 2020

How to find out which package a file belongs to on Linux/Unix.

This post shows how to find out which software package created a file on a Linux system. The way to go about this task is dependent on the package manager is used. This post shows how it is done in 3 of the most popular package manager: RPM (Redhat/Centos, etc.), dpkg (Debian/Ubuntu, etc.), and pkg (FreeBSD)

rpm -qf <path/to/file>
pkg which <path/to/file>
dpkg-query -S <path/to/file>

Running the commands on CentOs and Ubuntu to find which package created /etc/ssh/ssh_config will look like this:

rpm -qf /etc/ssh/ssh_config
openssh-clients-5.3p1-124.el6_10.x86_64

dpkg-query -S /etc/ssh/ssh_config
openssh-client: /etc/ssh/ssh_config