Cheat Sheets

RPM Cheat Sheet: rpm Query, Verify, Install Commands (PDF)

Nearly every file outside your home directory on a Fedora or Rocky system was put there by an rpm package, and rpm tells you which one. It answers what dnf glides over: your exact version, the package that owns a file, whether a package’s files still match the metadata from install time, and what a downloaded rpm will put where.

Original content from computingforgeeks.com - post 186060

All the output comes from Fedora 45 (RPM 6.1) and Rocky 10.2 (RPM 4.19), run in November 2026. Where the versions differ, mostly around signing keys, the difference gets its own section. Debian and Ubuntu readers get the same job done with the APT cheat sheet.

RPM Cheat Sheet (Quick Reference)

Queries run fine as any user; anything that installs, erases or rebuilds needs sudo, and so does verification, because files like sshd_config (mode 0600) can’t be read to compare digests without root. A trailing *.rpm means a package file you downloaded, not an installed package, and the -p variants read those files without touching the database.

Query installed packages

CommandWhat it does
rpm -q bashShow one package’s exact name-version-release
rpm -qi bashFull metadata: size, license, install date, signing key
rpm -ql sudoList every file the package installed
rpm -qc openssh-serverList only the package’s config files
rpm -q --requires bashList the dependencies the package needs
rpm -q --provides bashList what the package offers to other packages
rpm -qf /usr/bin/sudoShow which package owns a file
rpm -qaList every installed package
rpm -qa | wc -lCount installed packages
rpm -qa --lastList packages newest by install time first
rpm -q bash --qf '%{NAME} %{VERSION}-%{RELEASE} %{ARCH}\n'Print a custom format, one line per package

The -q family fails quietly on purpose. A package that isn’t installed prints package nginx is not installed and exits 1, so it chains into shell checks without extra flags. Nothing else in the tool prints a friendlier version, so learn the exit codes once and lean on them.

Query an rpm file

CommandWhat it does
rpm -qp pkg.rpmQuery a package file without installing it
rpm -qip pkg.rpmShow metadata for a package file
rpm -qlp pkg.rpmList the files inside a package file
dnf download jqFetch the current rpm into the current directory, no install

dnf download is the clean way to get a package file to poke at. On Fedora the download command is built into dnf5 itself; on Rocky it comes from dnf-plugins-core, and dnf download worked on the Rocky 10.2 lab image without installing anything first. The extraction section shows what to do with the file once you have it.

Verify installed packages

CommandWhat it does
sudo rpm -V openssh-serverCompare the package’s files against the metadata recorded at install time
sudo rpm -VaVerify every installed package; slow but the full picture
sudo dnf reinstall -y openssh-serverRestore missing files; an edited config file is kept as it is

A clean package prints nothing and exits 0. Any output is one line per file with a nine-character flag string, and the verify section decodes it.

Install, upgrade and erase

CommandWhat it does
sudo rpm -ivh btop-*.rpmInstall verbosely with progress bars
sudo rpm -ivh a.rpm b.rpmInstall several packages as one transaction
sudo rpm -Uvh pkg.rpmInstall if absent, otherwise upgrade and remove the old version
sudo rpm -e jqErase an installed package
sudo rpm --rebuilddbRebuild the rpm database indexes from the package headers

Reach for rpm -U over rpm -i unless you have a reason. On an installed package, -i is an error rather than an upgrade, and the install section shows the refusal you’ll get.

Extract rpm contents

CommandWhat it does
rpm2cpio pkg.rpm | cpio -idmv 2>&1Extract the payload into the current directory
rpm2cpio pkg.rpm | cpio -itList the payload contents without extracting

Extraction needs the cpio package; it was already present on both lab images, and dnf install cpio adds it if yours lacks it. It never runs scripts, checks signatures or touches the rpm database, so it’s the safe way to pull a config or a binary out of a package you don’t want to install.

Signatures and keys

CommandWhat it does
rpmkeys --checksig pkg.rpmVerify the package’s digests and signatures
rpm -q gpg-pubkeyList imported signing keys, stored as pseudo-packages
rpmkeys --listList keys with their user IDs
sudo rpmkeys --import vendor.ascImport a vendor’s public signing key from a file
sudo rpmkeys --import https://dl.rockylinux.org/pub/rocky/RPM-GPG-KEY-Rocky-10Import a key straight from an https URL
rpmkeys --export <fingerprint> > key.ascSave an imported key to a file (RPM 6)
sudo rpmkeys --erase <fingerprint>Remove a key; RPM 4.19 also takes the 8-hex key ID

On Fedora 45 the gpg-pubkey names look different from older guides, because RPM 6 records a full fingerprint where RPM 4 recorded a short key ID. The RPM 6 section shows both. For key and certificate work that sits outside packages, the OpenSSL cheat sheet picks up where rpmkeys stops.

Find the Package That Owns a File

Ask rpm -qf when you want to know what put a file on your system. It works on binaries, libraries and config files alike, because the query only reads the database rather than the file itself. The answer is the owning package’s full name-version-release:

rpm -qf /usr/bin/sudo
rpm -qf /etc/ssh/sshd_config

Both queries resolve on Fedora 45, and they show the two halves of the system at once. The sudo binary belongs to the sudo package, while the daemon config belongs to openssh-server, so a change to each file means something different:

rpm -qf resolving /usr/bin/sudo and /etc/ssh/sshd_config to their owning packages on Fedora 45

The config case matters when you’re hardening a server. A setting in /etc/ssh/sshd_config is a claim about openssh-server, not sudo, and rpm -V openssh-server is the check that watches it. That’s the next section.

Check Package Details and File Lists

rpm -qi prints the metadata block for one package. On an unfamiliar system, read the size, install date and signature lines, because together they tell you what the package is, when it arrived and whether the distro signed it:

rpm -qi bash output on Fedora 45 showing size, install date and the RSA/SHA256 signature key ID

The file-side queries complete the picture: rpm -ql lists everything the package installed, and rpm -qc narrows that to config files. For dependencies, --requires answers what the package needs and --provides what it offers the rest of the system:

rpm -q --requires bash | head -4

On Rocky 10.2 the first four entries mix a file path, a versioned capability and a shared library, which is how rpm records most dependencies:

/usr/bin/sh
config(bash) = 5.2.26-6.el10
filesystem >= 3
libc.so.6()(64bit)

Fedora 45 prints the same four lines with its own bash release in the config(bash) entry. The -qp variants run the same queries against a downloaded package file instead of the database. Use them on a third-party rpm before you let it anywhere near an install.

Every query tag --qf accepts is listed on rpm.org’s queryformat manual page, if you want formats beyond the name-version-release one above.

Verify Installed Packages with rpm -V

rpm -V compares the files on disk against the size, digest, mode, owner and timestamps recorded at install time. It is the tool for the did-something-change-this-package question, and it stays deliberately quiet when everything matches. Here one config file was edited and another deleted, then the repair was attempted twice:

rpm -V flagging an edited sshd_config and a missing PAM file on Fedora 45, dnf reinstall restoring only the missing file, and a clean verify after moving the edited config aside

Read the flag string left to right, one column per check:

  1. S means the file’s size differs from the recorded one
  2. 5 means the digest differs, so the content changed
  3. T means the modification time moved
  4. The trailing c marks the file as a config file

Those are the columns this sheet’s captures hit. The other columns cover mode, device, symlinks, user, group and capability changes, and the rpm manual lists all nine. A deleted file prints as missing instead of a flag string. In the capture, an appended line to /etc/ssh/sshd_config shows as S.5....T. c and a removed PAM snippet prints as missing. With two packages failing, the exit code was 2; a single failing package exits 1.

The repair is where most guides get it wrong. dnf reinstall put the missing PAM file back, but it left the edited sshd_config alone, because it’s a config file you changed and the packaged copy in the same version didn’t, so rpm keeps yours. Rocky 10.2 behaved the same way. To get the packaged copy back, move your edited file aside and reinstall, and rpm -V goes quiet with exit code 0. Then diff your copy against the fresh one and carry over the changes you actually meant.

For a whole-system audit, rpm -Va walks every installed package. On the freshly cloned Fedora 45 VM it checked 554 packages in under 6 seconds and printed 8 lines, none of them a real problem:

..5....T.  c /etc/cloud/cloud.cfg
.M.......    /run/cloud-init
.M.......  g /usr/lib/sysimage/libdnf5/environments.toml
.M.......  g /usr/lib/sysimage/libdnf5/groups.toml
.M.......  g /usr/lib/sysimage/libdnf5/modules.toml
.M.......  g /usr/lib/sysimage/libdnf5/nevras.toml
.M.......  g /usr/lib/sysimage/libdnf5/packages.toml
.M.......  g /usr/lib/sysimage/libdnf5/system.toml

The M column is a mode change and the g marker means a ghost file, one the package claims but creates at run time, so dnf’s state files always show up here. Rocky 10.2 gave 7 lines in about 4 seconds. A long-running server reports far more, mostly config files you edited on purpose, so filter out the c and g lines first and look at what’s left.

Install, Upgrade and Erase with rpm

Use rpm directly when you have a package file in hand, usually one you downloaded or built. The -ivh flags mean install, verbose output and a hash progress bar. Two packages install in one transaction, which matters when they depend on each other:

rpm -ivh installing hicolor-icon-theme and btop together as root on Fedora 45

rpm refuses, with named reasons, in the two cases you’ll actually hit. A missing dependency stops the transaction before anything is written. Installing an already-present package is an error rather than a silent no-op:

rpm -ivh failing with a hicolor-icon-theme dependency error and an already-installed error on Fedora 45

Both failures recover cleanly and leave nothing behind:

  1. For the missing dependency, run sudo dnf install ./btop-*.rpm and let dnf resolve the rest from the configured repos
  2. For the already-installed error, use rpm -Uvh when the file is a newer version; with the same version -Uvh refuses too (exit code 2 in the lab), so reach for dnf reinstall
  3. To start over, erase the package with rpm -e and install it again

-U also installs a package that isn’t there yet, which is why it’s the safer default. On Fedora 45, after erasing tree, the same file went straight back in:

sudo rpm -Uvh tree-2.3.1-2.fc45.x86_64.rpm

rpm verifies the package, prepares the transaction and installs it, with the hash bars the h flag asks for:

Verifying...                          ########################################
Preparing...                          ########################################
Updating / installing...
tree-2.3.1-2.fc45                     ########################################

Before the erase, the same command against the already-installed tree printed package tree-2.3.1-2.fc45.x86_64 is already installed and changed nothing. sudo rpm --rebuilddb, by contrast, prints nothing at all on success on either distro and exits 0; run it when rpm reports a damaged database, not as routine maintenance.

The dnf5 cheat sheet covers that repository-side workflow in depth, including the ./ path syntax dnf needs for a local file.

Erase failures read the same way. Removing jq on Fedora 45 stops because lvm2 needs it, and the same command on Rocky 10.2 stops because dracut-network does:

sudo rpm -e jq

The refusal names the dependent package, on Fedora with lvm2 as the reason:

error: Failed dependencies:
	jq is needed by (installed) lvm2-2.03.43-2.fc45.x86_64

Rocky 10.2 names a different package in the same format, and exits 1:

error: Failed dependencies:
	jq is needed by (installed) dracut-network-107-9.el10_2.x86_64

Nothing was removed in either case, so the system is exactly as it was before the command. Erase the dependent package too, or accept that this one stays, because the dependency is real and something on the system uses it. --nodeps will force the erase, but it leaves the dependent package holding a dependency that no longer exists, and every later transaction on that system gets to rediscover the breakage.

Extract Files from an rpm Without Installing

rpm2cpio turns a package file into a cpio stream on stdout, and cpio -idmv unpacks it relative to your current directory. Nothing gets installed, no scripts run, and the database never hears about it. That’s what makes this the safe way to recover one config file or read a binary you don’t trust enough to install:

rpm2cpio piping a jq rpm through cpio as root and extracting usr/bin/jq on Fedora 45

The 2>&1 in the shown command matters because cpio -v writes its file listing to stderr. Merge the streams or the listing never appears. A grep -v build-id on the pipeline keeps the debug-link directories under usr/lib/.build-id/ out of the listing, because they’re not files you need.

After extraction the files land under ./usr/. ls -l usr/bin/jq confirms the binary is there with its original mode bits, so you can copy it into place or just read it. The mode comes from the package header. The root root owner only appears because this extraction ran as root; run it as your own user and the files belong to you, which is usually what you want for a throwaway copy.

To check what a package will install before extracting anything, list the payload instead:

rpm2cpio jq-1.8.2-5.fc45.x86_64.rpm | cpio -it | grep -v build-id

For the Fedora 45 jq package that’s ten paths plus cpio’s block count, with nothing written to disk:

950 blocks
./usr/bin/jq
./usr/lib64/libjq.so.1
./usr/lib64/libjq.so.1.0.4
./usr/share/doc/jq
./usr/share/doc/jq/AUTHORS
./usr/share/doc/jq/NEWS.md
./usr/share/doc/jq/README.md
./usr/share/licenses/jq
./usr/share/licenses/jq/COPYING
./usr/share/man/man1/jq.1.gz

rpm -qlp on the same file printed the identical ten paths from the metadata side, without the leading ./, so use whichever is already in your fingers. If you’re pulling in a newer application than the repo ships, like the rpm route of installing LibreOffice on Fedora, a two-second payload check tells you what will land where.

Check Signatures and Manage Keys with rpmkeys

rpmkeys --checksig verifies a package file’s digests and its signatures against the keys rpm knows. A package from the distro repos checks clean because its key is already in the database:

rpmkeys --checksig jq-1.8.2-5.fc45.x86_64.rpm

The healthy answer names both layers and exits 0:

jq-1.8.2-5.fc45.x86_64.rpm: digests signatures OK

The failure case is worth seeing once, because it’s what a package signed by a key you never imported looks like. A package whose contents were altered fails the digests as well. Here the Fedora signing key was removed from the keyring first, and the same check now refuses. Exit code 1 is your signal, because rpm prints nothing louder than that:

rpmkeys --list, --export and --erase on Fedora 45, checksig failing with SIGNATURES NOT OK, then passing after rpmkeys --import

digests SIGNATURES NOT OK with exit code 1 means the package itself is intact but no imported key vouches for it. The capture walks the whole cycle in order:

  1. Export the current key with rpmkeys --export so you can put it back
  2. Remove it from the keyring with rpmkeys --erase and its fingerprint
  3. Run the same rpmkeys --checksig, which now prints digests SIGNATURES NOT OK and exits 1
  4. Import the saved key with rpmkeys --import
  5. Run the check again, which prints digests signatures OK once more

Older guides use rpmkeys --delete for step 2. It still works on RPM 6.1, but the rpmkeys manual marks --delete and -d as deprecated in favour of --erase and -e. Pointing rpmkeys --import at a path that doesn’t exist fails with import read failed(2) and changes nothing, so a typo costs you nothing.

--import also takes an https URL, which saves the download step for a vendor key. On Rocky 10.2 the same cycle ran against the distro key, re-imported straight from Rocky’s mirror:

Rocky Linux 10.2 listing gpg-pubkey-6fedfc85, erasing it with rpmkeys --erase, and re-importing the key straight from an https URL

Two details differ from Fedora. RPM 4.19 accepts the short key ID 6fedfc85 for --erase, and it has no --export, so keep the vendor’s .asc file or its URL if you plan to put a key back. The URL import worked on Fedora 45 as well. Only import from a URL you trust over https, because whatever key it serves will vouch for packages from then on.

Imported keys are stored as pseudo-packages named gpg-pubkey, so the ordinary query family manages them. On Rocky 10.2 they look the way every older guide shows, with a short key ID in the version field, and the distro’s key files still sit in /etc/pki/rpm-gpg/:

Rocky 10.2 showing gpg-pubkey-6fedfc85, the keys in /etc/pki/rpm-gpg and a clean rpmkeys checksig

rpm -qi on that pseudo-package prints the usual metadata block, with Group : Public Keys and no signature of its own. rpm -e gpg-pubkey-6fedfc85-682ae1a9 also removes a key and runs silently on Rocky 10.2. On Fedora 45 the same form still worked but printed this warning:

warning: erasing gpg-pubkey packages is deprecated; use rpmkeys --delete 4f50a6114cd5c6976a7f1179655a4b02f577861e

The warning still names --delete, the alias the manual now calls deprecated. --erase runs the same operation, so use rpmkeys --erase on both distros.

What the New RPM Major Changes for Key Handling

Fedora 45 ships RPM 6, while Rocky 10 and the other Enterprise Linux rebuilds still ship the 4.x series, and the difference lands exactly on the commands this sheet covers. The visible change is the key name: RPM 4 records an 8-hex key ID, so rpm -q gpg-pubkey prints gpg-pubkey-6fedfc85-682ae1a9, while RPM 6 records the key’s full fingerprint in that field instead (40 hex characters for Fedora’s v4 key), so the same query prints a much longer version string. Any guide or script that matches the old short form comes up empty on Fedora, which is why the key-listing command below matters more than the pseudo-package name.

A second difference trips up old scripts, and it comes from Fedora’s packaging rather than from RPM 6. On Rocky the vendor key files sit in /etc/pki/rpm-gpg/, as the capture above shows. On Fedora 45 that directory is empty, because the fedora-gpg-keys package now ships the files under /usr/share/pki/rpm-gpg/ (see its Fedora 45 file list). On both distros the imported keys themselves live in the rpm database, and rpmkeys --list reads them from there:

rpmkeys --list

On Fedora 45 each line prints the 40-character fingerprint followed by the key’s user ID:

4f50a6114cd5c6976a7f1179655a4b02f577861e Fedora (45) <[email protected]> public key

The same command works on Rocky 10.2’s RPM 4.19 build, but it prints the short form, 6fedfc85-682ae1a9: Release Engineering (Rocky Linux 10), as the Rocky capture above shows. The practical rule: verify with rpmkeys --checksig, which works the same on both series, and only touch the gpg-pubkey naming when you’re scripting against one distro. Apart from the key handling covered in this section (naming, --export and the rpm -e gpg-pubkey warning), every command run on both releases behaved the same way.

Keep this page open next to the terminal the first few times and the query flags will stick faster than you expect. When a command here refuses, the refusal text names the package or dependency to look at next, which is usually all the hint you needed. For everything repository-side, hand the job to dnf and keep rpm for the questions only it answers. This sheet is part of the site’s free pack; the cheat sheets hub has the rest, from dnf5 to kubectl.

Keep reading

How to Upgrade Fedora 44 to Fedora 45 (GUI, CLI and Rollback) Fedora How to Upgrade Fedora 44 to Fedora 45 (GUI, CLI and Rollback) Things to Do After Installing Fedora 45 Workstation Fedora Things to Do After Installing Fedora 45 Workstation Enable RPM Fusion and Multimedia Codecs on Fedora 45 / 44 / 43 Fedora Enable RPM Fusion and Multimedia Codecs on Fedora 45 / 44 / 43 Things to Do After Installing Rocky Linux 10 / AlmaLinux 10 AlmaLinux Things to Do After Installing Rocky Linux 10 / AlmaLinux 10 uv Cheat Sheet: Python Package Manager Commands (PDF) Cheat Sheets uv Cheat Sheet: Python Package Manager Commands (PDF) Fedora 45 vs Bazzite for Gaming: Steam, Updates and NVIDIA Fedora Fedora 45 vs Bazzite for Gaming: Steam, Updates and NVIDIA

Leave a Comment

Press ESC to close