To list files installed by an RPM package, you use the rpm -ql command followed by the package name. This command displays the full paths of every file the package placed on your system, which is the most direct and reliable method.
Understanding RPM and Its File Database
RPM (Red Hat Package Manager) is the package management system used by Red Hat-based Linux distributions, including Fedora, CentOS, and RHEL. When you install an RPM package, the system records metadata about it—including the complete list of files it installs—in a local database. This database is the backbone of package management, allowing you to query, verify, and remove packages cleanly.
The file list is stored as part of the package’s metadata. Each entry includes the absolute path, file type, permissions, ownership, and checksums. This information is not just for reference; it enables the system to verify the integrity of installed files and to know exactly what to remove when you uninstall a package.
The Primary Command: rpm -ql
The most common way to list files installed by an RPM package is the -q (query) option combined with -l (list). The syntax is:
rpm -ql <package-name>
For example, to see all files installed by the bash package, you would run:
rpm -ql bash
The output is a simple list of absolute file paths, one per line. This works whether the package is installed or not, as long as the RPM file is available or the package is installed. If the package is not installed, you can query the RPM file directly:
rpm -qlp /path/to/package.rpm
The -p flag tells RPM to query the package file instead of the installed package database.
Using rpm -q with Other Options
The -q option is versatile and can be combined with other flags to get different information. Here are some useful combinations:
rpm -qa– Lists all installed packages.rpm -qf /path/to/file– Finds which package owns a specific file.rpm -qc <package>– Lists only configuration files.rpm -qd <package>– Lists only documentation files.rpm -qs <package>– Lists files with their state (normal, missing, etc.).
Verifying Installed Files with rpm -V
Beyond listing, you can verify that the files installed by a package match the original checksums stored in the RPM database. The command:
rpm -V <package-name>
This checks each file’s size, permissions, ownership, and checksum against the database. If any file has been modified, deleted, or corrupted, the command will output a line indicating the discrepancy. This is particularly useful for security auditing or troubleshooting system issues.
For example, if a configuration file was edited manually, rpm -V will flag it with a c in the output, indicating a change. This does not mean the change is wrong; it simply alerts you to differences from the package’s original state.
Finding Which Package Owns a File
Often you may encounter a file and wonder which RPM package it came from. The -qf option answers this directly:
rpm -qf /etc/hostname
This command returns the package name that owns the specified file. This is handy when you want to know what package to update or remove to affect that file. Note that the file must be installed on the system for this to work; if the file is not from an RPM package, the command will print an error.
Common Problems and Misconceptions
One common issue is that rpm -ql may list files that no longer exist on the system. This can happen if a file was manually deleted or if the package was partially removed. The RPM database still contains the original file list, but the files themselves are gone. To check for such discrepancies, use rpm -V as described above.
Another misconception is that rpm -ql lists all files that the package might install, including those created dynamically at runtime. In reality, RPM only lists files that are explicitly included in the package’s payload. Configuration files that are generated on first run, such as some application data files, are not listed because they are not part of the package.
Also, note that RPM does not track directories as files. The -l output may show directories, but they are listed separately from regular files. If you want to see only regular files, you can filter the output with grep or use the --dump option for more detailed information.
Alternatives: dnf and yum
On modern Fedora and RHEL systems, the dnf package manager is the front-end for RPM. While rpm -ql works, dnf offers a more user-friendly way to query packages:
dnf repoquery -l <package-name>
This command lists files from the repository, not just installed packages. It can also show files for packages that are not installed, as long as the repository metadata is available. The older yum command had a similar option:
yum repoquery -l <package-name>
While dnf is the modern replacement, yum is still present on some older systems. Both rely on the same RPM database for installed packages, but repoquery can query remote repositories.
Practical Examples and Use Cases
Let’s walk through a few practical scenarios where listing RPM files is useful.
Scenario 1: You want to know what a package installed. You just installed a new tool and want to see where the binaries and configuration files went. Run rpm -ql <package> and you’ll get the full picture. For instance, rpm -ql httpd will show all files for the Apache web server, including the binary, modules, and default configuration files.
Scenario 2: You need to back up configuration files. Before uninstalling a package, you might want to preserve its configuration files. Use rpm -qc <package> to list only configuration files, then copy them to a safe location. This is a common practice when migrating services.
Scenario 3: You suspect a file has been tampered with. Run rpm -V <package> to verify the integrity of all files. This is a standard security check. If you see output, it indicates a change; you can then investigate whether the change was intentional.
How to Choose the Right Command
With several options available, you might wonder which to use. Here’s a quick guide:
- If you need a quick list of files from an installed package, use
rpm -ql. - If you need to list files from a package file you have downloaded, use
rpm -qlp. - If you need to find which package owns a file, use
rpm -qf. - If you need to verify file integrity, use
rpm -V. - If you prefer a higher-level tool, use
dnf repoquery -l.
Frequently Asked Questions
Q: How do I list files installed by a package that is not currently installed?
You can use rpm -qlp with the path to the RPM file. Alternatively, if the package is available in a repository, use dnf repoquery -l to list files without installing it.
Q: What is the difference between rpm -ql and rpm -qa?rpm -ql lists files for a specific package, while rpm -qa lists all installed packages on the system. They serve different purposes: one is for file-level detail, the other for package inventory.
Q: Can I list files for a package that was installed via a dependency?
Yes, dependencies are installed as RPM packages, so you can query them just like any other package. Use rpm -qa to see all installed packages, then rpm -ql on the one you are interested in.
Q: Why does rpm -ql show files that don’t exist on my system?
This happens when files were manually deleted or the package was partially removed. The RPM database retains the original file list. Use rpm -V to identify missing or altered files.
Q: Is there a way to list only directories installed by a package?
You can filter the output of rpm -ql with grep to show only lines ending with a slash, or use rpm -ql --dump and inspect the file type field. However, there is no direct option to list only directories.
Summary
Listing files installed by an RPM package is a fundamental task for system administration. The rpm -ql command is the primary tool, and it can be combined with other options to get configuration files, documentation, or verification. Understanding how to use these commands helps you manage your system effectively, whether you are troubleshooting, preparing backups, or auditing security. Always consult the official RPM documentation or your distribution’s help pages for the most up-to-date details.