Linux: Querying with RPM

  • Service Provider

    All RPM query commands begin with rpm -q to indicate that we wish to query the RPM system.

    Our first example is to "query all". This will return a list of all RPM packages that have been installed on the system. This is a very long list and includes everything from the kernel to libraries to end user applications. This list is often thousands of packages long, but is very useful and informative.

    # rpm -qa

    You will get a lot of output from this command. Typically we only use this command to produce output meant to be further filtered in some way (often by grep) or to be output to a text file in order to be compared to packages on another system or recorded in a change management system. Examples:

    # rpm -qa | grep yum
    # rpm -qa > /tmp/complete_rpm_list

    The first example will show us all RPM packages that contain the word "yum", the second stores the complete RPM package installation list in a text file.

    Querying the entire database installation list is handy, often we only want to query for specific packages. Let's look at a system's YUM packages as an example:

    # rpm -qa | grep yum

    What if we only wanted to know about yum itself? We can just use the -q flag and the package name. Obviously, we need to already know the package name that we are looking for.

    # rpm -q yum

    We can also use RPM to query the changelog for a package. Want to know how each patch level of YUM has changed things?

    # rpm -q --changelog yum

    I won't show the output here as it is very long, but try that yourself. Can make for some interesting reading although is rarely used in the field.

    We can ask RPM to tell us a bit about an installed package with the "-qi" info flag. This is the "info" flag and can be extremely useful.

    # rpm -qi yum
    Name        : yum
    Version     : 3.4.3
    Release     : 132.el7.centos.0.1
    Architecture: noarch
    Install Date: Fri 15 Jan 2016 02:47:33 PM UTC
    Group       : System Environment/Base
    Size        : 5761223
    License     : GPLv2+
    Signature   : RSA/SHA256, Thu 03 Dec 2015 03:39:58 PM UTC, Key ID 24c6a8a7f4a80eb5
    Source RPM  : yum-3.4.3-132.el7.centos.0.1.src.rpm
    Build Date  : Thu 03 Dec 2015 03:33:42 PM UTC
    Build Host  :
    Relocations : (not relocatable)
    Packager    : CentOS BuildSystem <>
    Vendor      : CentOS
    URL         :
    Summary     : RPM package installer/updater/manager
    Description :
    Yum is a utility that can check for and automatically download and
    install updated RPM packages. Dependencies are obtained and downloaded
    automatically, prompting the user for permission as necessary.

    From this output you can see that there is a lot to learn about a package. We can see even details concerning the license, how the package is signed, when it was built and where, who the vendor is and even a description of what the package does. This tends to be a commonly used option.

    One of the more useful commands is the "long" package listing with "-ql". This output shows all files that are provided by (or as we say "owned by") the package in question. Again this is a long listing so run this yourself.

    # rpm -ql yum

    The last query option that we will learn about here is the ability to query a specific file to learn what package owns it, the inverse of the long listing that we just saw. This is a very useful tool as we often want to know why files exist in our systems. So the new flag is the "f" or "file" flag and takes a filename as the information that we pass in and it returns to us the name of the RPM package.

    # rpm -qf /usr/share/yum-cli

    There are numerous RPM query options but these cover nearly all use cases and are the ones that an active administrator of an RPM-based system should know. Use the command reference to find more options when needed.

Looks like your connection to MangoLassi was lost, please wait while we try to reconnect.