Listing Files In a Package With DNF

By | 2020-01-04

Listing files in a package with dnf is easy. Just follow the example below:

# dnf repoquery -l crontabs
Last metadata expiration check: 0:12:18 ago on Sat 04 Jan 2020 09:40:27 AM EST.
/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly
/etc/crontab
/etc/sysconfig/run-parts
/usr/bin/run-parts
/usr/share/licenses/crontabs
/usr/share/licenses/crontabs/COPYING
/usr/share/man/man4/crontabs.4.gz
/usr/share/man/man4/run-parts.4.gz

Replace crontabs with the name of the package you wish to see the contents of.

If the package is already installed, you can use the rpm -ql command:

# rpm -ql crontabs
/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly
/etc/crontab
/etc/sysconfig/run-parts
/usr/bin/run-parts
/usr/share/licenses/crontabs
/usr/share/licenses/crontabs/COPYING
/usr/share/man/man4/crontabs.4.gz
/usr/share/man/man4/run-parts.4.gz

Determining Which Package Provides a File

If you are trying to figure out which package gives you a file you need, a common occurrence when installing things from source, follow this example:

# dnf provides ifconfig
Last metadata expiration check: 0:04:59 ago on Sat 04 Jan 2020 07:26:20 AM EST.
net-tools-2.0-0.51.20160912git.el8.i686 : Basic networking tools
Repo        : BaseOS
Matched from:
Filename    : /usr/sbin/ifconfig

net-tools-2.0-0.51.20160912git.el8.x86_64 : Basic networking tools
Repo        : BaseOS
Matched from:
Filename    : /usr/sbin/ifconfig

Replace ifconfig with the name of the file you are looking for. In the example, there are two different packages that provide the file /usr/sbin/ifconfig. The first package provides a version for the 32-bit i686 instruction set, the second for the amd64 instruction set. In the vast majority of cases, choose the amd64 version.

Alternatively, if you have the full path to the file, you can get a more concise output:

# dnf repoquery --file /usr/sbin/ifconfig
Last metadata expiration check: 0:11:38 ago on Sat 04 Jan 2020 07:35:58 AM EST.
net-tools-0:2.0-0.51.20160912git.el8.i686
net-tools-0:2.0-0.51.20160912git.el8.x86_64

If the file is already on your system, there is a third way using the rpm -qf command:

# rpm -qf /usr/bin/rpm
rpm-4.14.2-11.el8_0.x86_64

References

See Also