Red Hat Package Manager (RPM) is a powerful package management system that is used to install, update, remove, query, and verify software packages on Linux operating systems, especially RHEL and its derivatives like CentOS, Rocky Linux, AlmaLinux etc.

An RPM package file contains binary files, configuration files, documentation files, scripts and other components that comprise a software application or module. When an RPM package is installed, all the files contained within it get extracted and placed in appropriate locations on the Linux file system.

As a Linux system administrator or power user, it is often required to find out what files are installed by a particular RPM package. This helps in troubleshooting issues related to missing configs, locating documentation or identifying the binary executables provided by an application.

There are several useful RPM commands and options that can list the files inside an RPM package without actually installing it. This makes RPM a very versatile package manager.

In this comprehensive guide, we will explore the different methods to list files that are part of an RPM package in Linux.

Fundamentals of RPM Packages

Before we get into the various commands, let us briefly understand some basics about RPM packages.

  • RPM files use the .rpm extension (e.g. httpd-2.4.37-30.el7.x86_64.rpm)
  • Inside the RPM file is a cpio archive of all files that comprise the package
  • An RPM package contains metadata that describes the package contents including:
    • Name, version, release number
    • Packager details
    • Dependencies
    • File listings
    • Change logs
    • Licensing information
  • RPM package filenames conventionally follow the naming format: {name}-{version}-{release}.{architecture}.rpm

So an RPM file contains both the binaries that need to be installed, as well as information about the package itself.

By querying an RPM file, we can retrieve metadata about the package without actually installing it. The RPM utilities provide a rich set of options to list this information.

Listing Files in an RPM Package

Now let us go through some practical examples of how to list files inside an RPM file.

1. List Files in Downloaded RPM Package

For this demonstration, we will use an RPM package file named telnet-server-1.2-8.el7.x86_64.rpm which has been downloaded from a repository.

To display all files contained within this RPM package without installing it, we use the rpm command with the -qp options:

$ rpm -qpl telnet-server-1.2-8.el7.x86_64.rpm

/etc/xinetd.d/telnet
/usr/libexec/telnetlogin
/usr/sbin/in.telnetd

Here:

  • -q: Query mode
  • -p: Query an uninstalled package file
  • -l: List files

This prints out all files that would get installed on the system if this RPM was installed.

We can also view additional metadata about the package using -i option instead of -l. This provides info like package description, version, licenses, dependencies etc.

$ rpm -qip telnet-server-1.2-8.el7.x86_64.rpm

So -ql gives just the files listing, while -qi provides complete package details.

2. List Files in Installed RPM Package

To query files that have been installed by an RPM package, we use the same rpm command but without the -p option:

$ rpm -ql telnet-server

/etc/xinetd.d/telnet
/usr/libexec/telnetlogin  
/usr/sbin/in.telnetd

The above command displays files that were actually installed from the telnet-server package.

We can also verify this by checking the package details:

$ rpm -qi telnet-server

Name        : telnet-server
Version     : 1.2
Release     : 8.el7
Architecture: x86_64
Install Date: Tue 05 Jul 2022 10:32:02 AM IST
Group       : System Environment/Daemons
Size        : 48604
License     : BSD
Signature   : RSA/SHA256, Mon Jun 20 22:49:29 2022, Key ID 24c6a8a7f4a80eb5
Source RPM  : telnet-server-1.2-8.el7.src.rpm
Build Date  : Mon 20 Jun 2022 10:49:29 AM IST
Build Host  : builder10.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://github.com/rpm-software-management/telnet-server
Summary     : The telnet server and client programs
Description :
The telnet package provides the telnet client and server programs.
Telnet allows users to log in to remote systems over a network and
execute commands remotely.

This displays complete information about the installed telnet-server package including the list of files.

3. List Files Using Yum

On yum-based systems like RHEL, CentOS, AlmaLinux we can also utilize yum to query package contents:

$ yum list telnet-server

Installed Packages
telnet-server.x86_64        1.2-8.el7               @anaconda

This verifies telnet-server is installed. To view the files:

$ yum list --installed telnet-server

Installed Packages
telnet-server.x86_64        1.2-8.el7         @anaconda   
/etc/xinetd.d/telnet
/usr/libexec/telnetlogin
/usr/sbin/in.telnetd

So yum provides an easy way to identify installed packages and list package files.

4. List Files in RPM Database

The RPM database keeps track of all packages installed on the system along with their contents.

We can query the RPM db to find out package files without having the original .rpm file:

$ rpm -ql telnet-server

/etc/xinetd.d/telnet
/usr/libexec/telnetlogin
/usr/sbin/in.telnetd  

This produces same output as having the RPM file, except it draws info solely from database.

Listing Files in Enterprise Linux Distros

In enterprise Linux variants like RHEL, CentOS, Rocky Linux, AlmaLinux there are some additional tools that can be used to list package contents:

5. Using repoquery

The repoquery tool provided by yum-utils package queries Yum repositories for information on packages:

$ repoquery -l telnet-server

/etc/xinetd.d/telnet
/usr/libexec/telnetlogin
/usr/sbin/in.telnetd

To query an uninstalled package RPM from a repo:

$ repoquery -l ftp://localhost/telnet-server-1.2-8.el7.x86_64.rpm

/etc/xinetd.d/telnet
/usr/libexec/telnetlogin
/usr/sbin/in.telnetd

repoquery is useful for systems running RHEL, CentOS, AlmaLinux etc.

6. Using dnf

On Fedora and latest RHEL versions, DNF is the default package manager instead of Yum.

Similar to repoquery, we can utilize dnf to list contents of an installed package:

$ dnf repoquery -l telnet-server 

/etc/xinetd.d/telnet
/usr/libexec/telnetlogin
/usr/sbin/in.telnetd

DNF also provides rich package management capabilities like Yum.

Listing Files in DEB-Based Distros

On DEB package based systems like Ubuntu, Debian, Linux Mint following methods are suggested:

7. Using dpkg

dpkg is the package manager in apt-based distros that can be used for querying DEB packages:

$ dpkg -L package_name

For instance:

$ dpkg -L apache2  

/.
/usr
/usr/share
/usr/share/doc
...
... 

This prints all files installed from apache2 package along with their filesystem paths.

8. Using dpkg-query

An alternate approach is using dpkg-query which also displays contents of a DEB package:

$ dpkg-query -L package_name

/.
/usr
/usr/share 
...

Conclusion

Listing contents of software packages helps debug issues related to missing files, outdated configs or finding package components like documentation, scripts, licenses etc.

RPM and DEB – the two most popular packaging systems provide utilities to query and list files contained inside them.

For RPM packages, we can use the rpm, yum, dnf and repoquery commands with appropriate options to display a list of all files and details.

Similarly for DEB packages, the dpkg and dpkg-query tools come handy to show package files.

I hope this comprehensive guide was helpful in understanding how to list files inside packages on Linux systems like RHEL, CentOS, Ubuntu, Debian etc. Usage of these commands shall aid administrators and developers in better managing the Linux environment.

Similar Posts

Leave a Reply

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