How to List Installed RPM Packages on Linux

The rpm commands are used rpm based distros like CentOS, Fedora, Opensuse and RHEL. Modern Linux distros use yum and DNF package manager which has more features.

This tutorial explains the options that can be added to the rpm command (Redhat Package Manager) to list packages in Linux.

1) List all installed packages

To query the whole RPM database, we will use -qa option (query all) to list all the installed packages in Linux.

# sudo rpm -qa

2) List installed specific package

You can filter the rpm -qa results using grep command to list specific package.

The following command will list specific packages related to 'ssh'.

# rpm -qa | grep ssh
sample output

Use the following command to find the installation date for a specific package

# rpm -q --last openssh
openssh-5.3p1-118.1.el6_8.x86_64              Wed 01 Mar 2017 08:30:12 PM UTC

3) List Detailed information about a package

To List detailed information about the package like version, release, install date size and signature, use qi option. For example, let's check the detailed information of 'openssh' package

# rpm -qi openssh
rpm list package details

4) List Installed package by querying a file

We installed ssh from the openssh-server-5.3p1-84.1.el6.x86_64 package. We can use -qf option (query file) with rpm command on a configuration file.

The following example will list the package name related to the file ('/etc/ssh/sshd_config') mentioned the command:

# rpm -qf /etc/ssh/sshd_config

5) Display all files installed by a package

We will use -ql option with rpm command to show all the files of this installed package on the system.

# rpm -ql openssh-server-7.4p1-16.el7.x86_64

6) List only configuration files of the package

We will use -qc option with rpm command to displays configuration file related to package.

# rpm -qc openssh-server-7.4p1-16.el7.x86_64

7) List only documentation files of the package

We will use -qd option (query documentation) with rpm command to list only documentation files.

# rpm -qd openssh-server-7.4p1-16.el7.x86_64

8) Count total number of installed package

In Linux we can use wc command to count so we can pipe it rpm query command to get total count of installed packages.

# rpm -qa | wc -l

If you are using yum or dnf package manager then use the following command:

# yum list installed | wc -l
# dnf list installed | wc -l
# repoquery -a --installed | wc -l

9) List all installed package using repoquery command

In new version of CentOS, RHEL and Fedora it support using repoquery command to list all installed packages. If you are using dnf package manager then install ' dnf-utils' and for yum package manager install 'yum-utils'  in-order to use repoquery.

# dnf install dnf-utils
# yum install yum-utils

Run the following command to list all installed package using repoquery command:

# repoquery -a --installed

10) List installed packages from specific repository

You can list installed packages from a specific repository like EPEL repo on RHEL or CentOS 7 or CentOS 8 distros.

The following command list all packages installed from 'EPEL" repository:

# yum list installed | grep @epel

Yumdb is another command available to list installed packages from specific repo. Yumdb comes with 'yum-utils' package, so make sure to install it.

The following yumdb command will display all installed packages from 'EPEL' repo:

# yumdb search from_repo epel

11) How to restore configuration file from RPM package

If for some reason a file has been damaged or got deleted from the system, we can start with the rpm -qf query option to find out from what package the file originated. Next use rpm2cpio | cpio -idmv to extract the files from the package. Consider the ssh example:

Assuming that the /etc/ssh/sshd_config file has been deleted and we may not want to reinstall ssh, so we will restore the file using the steps below.

  1. The below command shows that the file comes from the openssh-server-7.4p1-16.el7.x86_64 Package.
    # rpm -qf /etc/init.d/sshd
  2. Download the Openssh rpm from its source
  3. Copy openssh-server-7.4p1-16.el7.x86_64 package file to /tmp directory or any other directory of your choice.
  4. Use rpm2cpio | cpio -idmv to extract the package.

The commands we used in the above steps created a few subdirectories in /tmp. We can now copy it to its original location.


In this tutorial we learned different ways to list installed rpm packages in Linux. I hope you enjoyed reading and please leave your suggestions in the below comment section.

Leave a Comment