RPM has a local package database that stores information about packages, including name, version, release, package maintainer, software license, and where the files will be stored. You can use the rpm command to query this package database. By providing options to the rpm command you can narrow our search down to any of this metadata.
- [Instructor] RPM is used to install local software packages. One a package is installed, the RPM package database is updated with the package information. We can query that package database. We can also query a package directly, even if it isn't installed. In addition, we can query a file. In reality, it's looking through the package database for a reference to the file. This only works for files that belong to software packages. Let's use the RPM command to query the database. In a terminal, type in rpm, space, -qa, and hit enter.
The -q option tells RPM to query, and -a means all packages. We could specify the two options individually, but we can also place them next to each other as you see here. Because we haven't specified a package or a file to query, RPM will query the database. We can see from this list that there's a lot of packages installed. If you like to have a sorted list, just type it in to sort. It would be rpm, space, -qa, space, pipe, space, sort, and hit Enter. And now you have an alphabetical list.
Since we know everyone has bash installed, let's query that. Type in clear, and hit Enter. Now type in rpm, space, -qi for query information, space, bash, and hit Enter. Again, we haven't specified to query a package or a file, so this information is coming from the database. The -qi will show information about the package. In this information, we see name, version, release, install date, and more. Near the bottom, we see the description. We can also narrow our search based on single attributes.
Let's say we wanted to find all packages in the System Environment/Shells group. We can do this. We just need to specify it. Type in clear again, and then type in rpm, space, -qa, space, Group with a capital G equals, double quote, System with a capital S, space, Environment, with a capital E, slash, Shells, with a capital S, double quote, and hit Enter. This shows the packages that have been tagged with System Environment/Shells.
We can also show when all packages were installed sorted by date. Type in rpm, space, -qa, space, --last, and hit Enter. If we want to see where all the files in a package were installed, we use -ql for query list. Type in clear, and then type in rpm, space, -ql, space, yum, and hit Enter. This will query for the list of file paths. The yum command installs 180 different files into different directories. It's nice to have a database maintain these files.
If we want to slim this list down to just documentation, we can specify the -d option. Type in clear, and then type in rpm, space, -qd for query documentation, space, yum, and hit Enter. Or with could use the -c option to show only configuration files. Type in rpm, space, -qc, space, yum for query configuration files. If you find a file on disk and want to know what package it came from, we can query the database for this as well.
We'll use the -qf options. Type in rpm, space, -qf for query file, space, /bin/bash. That would be the path of the file. And hit Enter. This shows that the /bin/bash file came from the bash package. Being able to identify where software came from can help a lot in learning about our Linux system. What is really handy is combining the -qd for query documentation and -qf for query file options. Type in clear, and then type in rpm, space, -qdf, space, /bin/bash.
And this shows all of the documentation for the /bin/bash command. Any time you find a file on disk and want to know where the documentation is, use these options. We can also ask the database what this package provides using --provides. Type in clear, and then type in rpm, space, -q for query, space, --provides, space, bash, and hit Enter. These are the features that the bash package provides. If we want to see what it requires, we can type in rpm, space, -q, space, --requires, space, bash, and hit Enter.
Another interesting query option is --changelog. This lets us check the changes to the package. Type in clear, and then type in rpm, space, -q, space, --changelog, space, bash, and hit Enter. This will show all of the changes that have happened to this package. So far, we've only been creating the database. If we have an RPM file downloaded, we can create a package directly before it's installed. Let's make a directory to put our RPM's in. Type in mkdir, space, /tmp/packages, and hit Enter.
Make sure that you do not use sudo in this case. Now, let's download an RPM. We're going to use the yum tool to do this to save time. We need to install the yum download only plugin first, and then we'll download the httpd package. Type in sudo, space, yum, space, install, space, -y, space yum-plugin-downloadonly and hit Enter, and type in your password. Then, hit Enter again. As soon as that finishes, type in sudo, space, yum, space, install, space --downloadonly, space, --downloaddir=/tmp/packages, space, httpd.
What this is going to do is download the httpd packages into the /tmp/packages directory. Now, let's cd into /tmp/packages and then type in ls. Yum would normally install the RPM from the repository after downloading it; however, since we passed the --downloadonly option and specified the /tmp/packages directory with the --downloaddir option, it only downloaded the packages. Now that we've typed in ls, we can see that we have an httpd package, an httpd-tools package, and a mailcap package, all of which were downloaded with yum.
To query a package that hasn't been installed yet, we'll add the -p option to RPM. Type in clear, and then type in ls. Type in rpm, space, -qip, space, httpd-2, and then hit your Tab key so it fills out the line. And then hit Enter. When we queried the database, we just provided -qi. To query our package, we provide -qip. To get a list of all files inside the package and where they'll be installed, provide -l. Type in rpm, space, -qlp, space, httpd-2, and then hit your Tab key again to complete the line.
And then hit Enter. Many of the previous query options will also work on a package as well. Just make sure that you provide the -p option so it queries the package and not the database. For more information, check the man page for RPM by typing in man, space, rpm, and hit Enter.
Instructor Grant McWilliams covers network and internet services administration, kernel management, and intrusion prevention. He shows how to make your systems more efficient with virtualization, manage users and groups, and lock everything down with SELinux mandatory access control. Plus, get access to 25 PDF "cheat sheets" and 100 practice questions so you can solidify and test your knowledge.
- Installing Linux on a physical machine
- Managing systemd services
- Managing reoccurring jobs with cron
- Limiting system access
- Configuring networking
- Creating, editing, and moving files and directories
- Analyzing text with grep and regular expressions
- Installing software and packages
- Managing the kernel
- Managing users, accounts, and groups
- Setting permissions
- Using access control lists
- Securing Linux with SELinux
- Accessing Linux remotely
- Configuring local storage