How to List Files Installed From an RPM Package in CentOS?

RPM is a package management system utilized by Linux distributions (RHEL/CentOS). It is utilized to install, update, and manage software packages on these systems. RPM packages contain the file extension “.rpm” files, dependencies, and metadata needed to install and manage a specific software program. 

This guide will illustrate the step-by-step instructions to list files installed from an RPM package in CentOS. 

How to List Files Installed From an RPM Package in CentOS?

The “rpm” command interacts with RPM packages in CentOS. To list the files installed from a package, you can use the “ql” option, which stands for “query package files.” This option tells rpm to list the files installed from the specified package.

Syntax:

The basic syntax to list files from the RPM packages is provided below: 

$ rpm -ql <package-name>

In the above syntax, the “package-name” is the name of the RPM package you want to list the files for.

Example: List Files Installed From an RPM Package

An example is considered to see which files were installed as a package. For instance, execute the “rpm” command with the “ql” option specifying the “httpd” package:

$ rpm -ql httpd

The output lists all files and directories installed from the “httpd” package. The output presents the complete path of each file, beginning from the root directory.

How to List the Package That Belongs to a Specific File?

Users can utilize the “rpm” command with the “-qf” option to list the package that belongs to a specific file. For instance, the user must specify the file name to display the list of packages that is associated with it.

Syntax:

The basic syntax to list the package belonging to a specific file is written below:

$ rpm -qf <file-name>

In the above syntax, the “file-name” is the file to know the package which belongs to it. 

Example: Find the Package Belongs to a Particular File

This example will find the package that belongs to the file “/etc/httpd/conf/httpd.conf”. For instance, execute the “rpm” command with the “qf” option by mentioning the above .conf file:  

$ rpm -qf /etc/httpd/conf/httpd.conf

The output shows the package name as “httpd-2.4.6-97.el7.centos.5.x86_64”, which is installed from the file.

Conclusion

CentOS offers the “rpm -ql <package-name>” command to list all files installed from an RPM package. Additionally, users can utilize the “rpm -qf <file-name>” script to find the package that belongs to a specific file. This guide has explained the method to list files from the RPM package in CentOS.