ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Linux: Querying with RPM

    IT Discussion
    linux rpm sam linux administration centos rhel fedora suse opensuse
    1
    1
    1.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by

      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
      yum-metadata-parser-1.1.4-10.el7.x86_64
      yum-3.4.3-132.el7.centos.0.1.noarch
      yum-plugin-fastestmirror-1.1.31-34.el7.noarch
      

      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
      yum-3.4.3-132.el7.centos.0.1.noarch
      

      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  : worker1.bsys.centos.org
      Relocations : (not relocatable)
      Packager    : CentOS BuildSystem <http://bugs.centos.org>
      Vendor      : CentOS
      URL         : http://yum.baseurl.org/
      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
      yum-3.4.3-132.el7.centos.0.1.noarch
      

      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.

      1 Reply Last reply Reply Quote 4
      • 1 / 1
      • First post
        Last post