How to Find Which Package an Executable or File belongs to in RedHat/CentOS/Fedora?

Updated on September 2, 2017

Question: I would like to know if there’s a command in CentOS that allows me to find which package an executable or file or library belongs to? For example, how can I find which package contains /usr/bin/sha256sum executable or which package contains a /usr/lib64/libnss3.so library file.

Answer:

You can use rpm -qf command to find which package a given executable or file or library belongs to.

Format:

$ rpm -qf <executable/file/library>

find package linux

How to find a package that contains given executable

$ rpm -qf /usr/bin/sha256sum
 coreutils-8.4-37.el6_7.3.x86_64

How to find which package a library belongs to

$ rpm -qf /usr/lib64/libnss3.so
 nss-3.19.1-5.el6_7.x86_64

How to find which package a file belongs to

$ rpm -qf /etc/httpd/conf/httpd.conf
 httpd-2.2.15-47.el6.centos.1.x86_64

How to list only the package name without version information

You can use –queryformat option as shown below:

$ rpm -qf /usr/bin/sha256sum --queryformat '%{NAME}\n'
 coreutils

How to find all available repository packages that will provide an executable or file or library?

$ yum provides /usr/bin/sha1sum
Loaded plugins: auto-update-debuginfo, fastestmirror, refresh-packagekit,
: security
Loading mirror speeds from cached hostfile
* base: dallas.tx.mirror.xygenhosting.com
* epel: mirror.compevo.com
* epel-debuginfo: fedora-epel.mirror.lstn.net
* extras: repos.dfw.quadranet.com
* updates: pubmirrors.dal.corespace.com
coreutils-8.4-37.el6.x86_64 : A set of basic GNU tools commonly used in shell
: scripts
Repo : base
Matched from:
Filename : /usr/bin/sha1sum
coreutils-8.4-37.el6_7.3.x86_64 : A set of basic GNU tools commonly used in
: shell scripts
Repo : updates
Matched from:
Filename : /usr/bin/sha1sum
coreutils-8.4-37.el6_7.3.x86_64 : A set of basic GNU tools commonly used in
: shell scripts
Repo : installed
Matched from:
Other : Provides-match: /usr/bin/sha1sum

That’s it.

Was this article helpful?

Related Articles

Leave a Comment