1. Overview

RPM (Red Hat Package Manager) is the package management system used in several Linux distributions, such as Red Hat, Fedora, and openSUSE.

Sometimes, we may need to list the files in an RPM package. We can list the contents of a package by passing the name of the package file as an argument to the rpm command together with the -q and -l options. However, the RPM package file may not always be available.

In this tutorial, we’ll discuss how to list the contents of an RPM package when we don’t have the package file.

2. Sample Packages

We’ll inspect two packages in the package repository. They’re zlib-devel.x86_64 and iperf3.x86_64 packages. Let’s verify their existence in the repository:

$ dnf list installed | grep zlib-devel.x86_64
zlib-devel.x86_64                                1.2.11-31.el9                                @appstream
$ dnf list available | grep iperf3.x86_64
iperf3.x86_64                                        3.9-9.el9                                @appstream

The dnf list installed command lists the installed packages. On the other hand, the dnf list available command lists the available packages, i.e., non-installed ones.

We used the grep command to filter the output of dnf list. We see that zlib-devel.x86_64 is an already installed package, but the other one, iperf3.x86_64, isn’t installed.

3. Using rpm

We can check an already installed package’s content using rpm even if we don’t have the RPM package file. The name of the package instead of the RPM package file must be passed to the rpm command:

$ rpm -ql zlib-devel.x86_64
/usr/include/zconf.h
/usr/include/zlib.h
/usr/lib64/libz.so
/usr/lib64/pkgconfig/zlib.pc
/usr/share/doc/zlib-devel
/usr/share/doc/zlib-devel/algorithm.txt
/usr/share/doc/zlib-devel/example.c
/usr/share/man/man3/zlib.3.gz

We listed the contents of zlib-devel.x86_64 successfully. The -q option of rpm is for querying a package. The -l option is for listing the contents of a package.

Let’s try to list the contents of the non-installed package, iperf3.x86_64, using rpm:

$ rpm -ql iperf3.x86_64
Package iperf3.x86_64 is not installed

Therefore, we can’t list the contents of a non-installed package using rpm.

4. Using yum repoquery

YUM (Yellowdog Updater, Modified) is a package management utility based on the RPM Package Manager. The yum command is the primary tool for the management of the packages.

The yum repoquery command searches for packages matching a keyword:

$ yum repoquery zlib-devel.x86_64
zlib-devel-0:1.2.11-33.el9.x86_64
zlib-devel-0:1.2.11-34.el9.x86_64
zlib-devel-0:1.2.11-35.el9.x86_64
zlib-devel-0:1.2.11-36.el9.x86_64
zlib-devel-0:1.2.11-39.el9.x86_64

There are five different versions of the zlib-devel.x86_64 library in our system according to the output of yum repoquery zlib-devel.x86_64.

We can get the contents of a package by using the -l option of yum repoquery:

$ yum repoquery -l zlib-devel.x86_64
/usr/include/zconf.h
/usr/include/zlib.h
/usr/lib64/libz.so
/usr/lib64/pkgconfig/zlib.pc
/usr/share/doc/zlib-devel
/usr/share/doc/zlib-devel/algorithm.txt
/usr/share/doc/zlib-devel/example.c
/usr/share/man/man3/zlib.3.gz

We can use the same command for listing the contents of a non-installed package:

$ yum repoquery -l iperf3.x86_64
/usr/bin/iperf3
/usr/lib/.build-id
/usr/lib/.build-id/68
/usr/lib/.build-id/68/c883ce2871cea4095c3d54b9b15ddc3f396146
/usr/lib/.build-id/cd
/usr/lib/.build-id/cd/978bb88ed41a61b505a70e4d24e8628f55bf79
/usr/lib64/libiperf.so.0
/usr/lib64/libiperf.so.0.0.0
/usr/share/doc/iperf3
/usr/share/doc/iperf3/LICENSE
/usr/share/doc/iperf3/README.md
/usr/share/doc/iperf3/RELEASE_NOTES
/usr/share/man/man1/iperf3.1.gz
/usr/share/man/man3/libiperf.3.gz

Therefore, the yum repoquery command is an option for listing the contents of an installed or non-installed package in the YUM repository.

5. Using repoquery

The repoquery command is another alternative to get information about packages in YUM repositories. yum-utils package must be installed to use this command.

We can use its -l option to list the files in a package. Let’s check the contents of the zlib-devel.x86_64 package:

$ repoquery -l zlib-devel.x86_64
/usr/include/zconf.h
/usr/include/zlib.h
/usr/lib64/libz.so
/usr/lib64/pkgconfig/zlib.pc
/usr/share/doc/zlib-devel
/usr/share/doc/zlib-devel/algorithm.txt
/usr/share/doc/zlib-devel/example.c
/usr/share/man/man3/zlib.3.gz

Using repoquery with the -l option listed the contents of the zlib-devel.x86_64 package, as expected.

Let’s check the contents of the other package, iperf3.x86_64, using repoquery:

$ repoquery -l iperf3.x86_64
/usr/bin/iperf3
/usr/lib/.build-id
/usr/lib/.build-id/4b
/usr/lib/.build-id/4b/c883ce2871cea4095c3d54b9b15ddc3f396146
/usr/lib/.build-id/c9
/usr/lib/.build-id/c9/978bb88ed41a61b505a70e4d24e8628f55bf79
/usr/lib64/libiperf.so.0
/usr/lib64/libiperf.so.0.0.0
/usr/share/doc/iperf3
/usr/share/doc/iperf3/LICENSE
/usr/share/doc/iperf3/README.md
/usr/share/doc/iperf3/RELEASE_NOTES
/usr/share/man/man1/iperf3.1.gz
/usr/share/man/man3/libiperf.3.gz

repoquery also listed the contents of the non-installed package successfully. Therefore, the repoquery command is another option for listing the contents of an installed or non-installed package in the YUM repository.

6. Using dnf repoquery

DNF (Dandified YUM) is the modern version of YUM with more robust and advanced features. It’s the default package management utility in the new versions of RPM-based Linux distros.

The dnf command is the primary tool for the management of the packages. The yum command also exists in these distros for backward compatibility. In fact, yum is a symbolic link to dnf, for example in Red Hat 8.

The usage of dnf repoquery command is similar to yum repoquery. It searches for packages matching a keyword:

$ dnf repoquery zlib-devel.x86_64
zlib-devel-0:1.2.11-33.el9.x86_64
zlib-devel-0:1.2.11-34.el9.x86_64
zlib-devel-0:1.2.11-35.el9.x86_64
zlib-devel-0:1.2.11-36.el9.x86_64
zlib-devel-0:1.2.11-39.el9.x86_64

We can get the contents of a package by using the -l option of dnf repoquery:

$ dnf repoquery -l zlib-devel.x86_64
/usr/include/zconf.h
/usr/include/zlib.h
/usr/lib64/libz.so
/usr/lib64/pkgconfig/zlib.pc
/usr/share/doc/zlib-devel
/usr/share/doc/zlib-devel/algorithm.txt
/usr/share/doc/zlib-devel/example.c
/usr/share/man/man3/zlib.3.gz

We can use the same command for listing the contents of a non-installed package:

$ dnf repoquery -l iperf3.x86_64
/usr/bin/iperf3
/usr/lib/.build-id
/usr/lib/.build-id/68
/usr/lib/.build-id/68/c883ce2871cea4095c3d54b9b15ddc3f396146
/usr/lib/.build-id/cd
/usr/lib/.build-id/cd/978bb88ed41a61b505a70e4d24e8628f55bf79
/usr/lib64/libiperf.so.0
/usr/lib64/libiperf.so.0.0.0
/usr/share/doc/iperf3
/usr/share/doc/iperf3/LICENSE
/usr/share/doc/iperf3/README.md
/usr/share/doc/iperf3/RELEASE_NOTES
/usr/share/man/man1/iperf3.1.gz
/usr/share/man/man3/libiperf.3.gz

Therefore, we can use the dnf repoquery command to list the contents of an installed or non-installed package in the DNF repository.

7. Conclusion

In this article, we learned how to list the contents of a package when we don’t have the RPM package file.

Firstly, we learned that we can use the rpm command to list the contents of an installed package. Then, we examined the yum repoquery, repoquery and dnf repoquery commands. We saw that we can use the -l option of these commands to list the contents of an installed or non-installed package in the repository.