Keywords: YUM package manager | repoquery command | package content query | Linux system administration | DNF alternative
Abstract: This article provides an in-depth exploration of various methods for listing package contents in Linux systems using the YUM package manager. It begins by analyzing the limitations of traditional RPM commands, then focuses on solutions using the repoquery command from the yum-utils package, covering basic usage, common issue resolution, and DNF alternatives. The article also compares other related commands like rpm -ql and yum info, offering readers comprehensive knowledge of package content querying techniques. Through practical code examples and detailed analysis, this guide serves as an essential resource for system administrators and developers.
Introduction
In Linux system administration, understanding the specific files contained within software packages is a crucial aspect of daily operations. While the traditional rpm -qpil package.rpm command can list package contents, it requires users to know the exact location of the RPM file in the filesystem, which is often inconvenient in practical scenarios.
Overview of YUM Package Manager
YUM (Yellowdog Updater Modified) is an RPM-based package manager widely used in distributions like Fedora, Red Hat Enterprise Linux, and CentOS. Compared to direct RPM command usage, YUM offers advanced features including dependency resolution, repository management, and automatic updates.
Using repoquery Command to List Package Contents
yum-utils is a toolkit that extends YUM functionality, containing the repoquery command specifically designed for querying software repository information. repoquery supports multiple query modes, with the -l or --list option专门用于 listing files contained in packages.
Basic Usage
To list all files in a specific package, use the following command format:
$ repoquery -l package_nameFor example, querying the contents of the time package:
$ repoquery -l time
/usr/bin/time
/usr/share/doc/time-1.7
/usr/share/doc/time-1.7/COPYING
/usr/share/doc/time-1.7/NEWS
/usr/share/doc/time-1.7/README
/usr/share/info/time.info.gzThe output clearly displays all files and directories created by the package installation in the filesystem.
Handling Empty Query Results
Under certain system configurations, using repoquery -l directly may return empty results. This typically occurs with specific combinations of RPM, YUM, and repoquery versions. For instance, in environments with RPM v4.8.0, YUM v3.2.29, and repoquery v0.0.11, querying the rpm package might encounter this issue.
The solution is to add the --installed flag, forcing the query to target installed packages:
$ repoquery --installed -l rpmThis flag ensures the query addresses the actual installed package version on the system, avoiding inconsistencies between repository metadata and local installation status.
DNF as a Modern Alternative
With the evolution of Linux distributions, DNF (Dandified YUM) has gradually become the next-generation replacement for YUM. DNF addresses many performance issues of YUM while maintaining backward compatibility.
In systems supporting DNF, achieve the same result with:
$ dnf repoquery -l time
/usr/bin/time
/usr/share/doc/time-1.7
/usr/share/doc/time-1.7/COPYING
/usr/share/doc/time-1.7/NEWS
/usr/share/doc/time-1.7/README
/usr/share/info/time.info.gzDNF's repoquery subcommand offers functionality equivalent to repoquery in yum-utils, but with better performance and a more modern codebase.
Comparative Analysis of Related Commands
rpm -ql Command
While this article primarily discusses YUM-related tools, understanding traditional RPM commands remains valuable. rpm -ql package_name directly lists files of installed packages without requiring additional tools:
# rpm -ql php-fpm
/etc/php-fpm.conf
/etc/php-fpm.d
/etc/php-fpm.d/www.conf
/etc/sysconfig/php-fpm
...
/run/php-fpm
/usr/lib/systemd/system/php-fpm.service
/usr/sbin/php-fpm
/usr/share/doc/php-fpm-5.6.0
/usr/share/man/man8/php-fpm.8.gz
...
/var/lib/php/sessions
/var/log/php-fpmThis method's advantage lies in not requiring yum-utils installation and faster execution. The drawback is it can only query installed packages, not available but uninstalled packages in repositories.
YUM Information Query Commands
YUM itself provides some information query capabilities. The yum info package_name command displays detailed package information, similar to rpm -q --info package_name, but additionally shows the source repository of the package.
For example, querying information about the abrt package:
$ yum info abrtThe output includes a From repo: line identifying the YUM repository containing the RPM package.
Furthermore, the yumdb info package_name command provides more detailed database information, including package checksums, installation commands, and installation reasons metadata.
Practical Application Scenarios
Package Verification and Auditing
During security audits and system verification, administrators need to confirm whether packages contain expected files or check for anomalous files. repoquery -l offers quick viewing of package contents, aiding in identifying potential security risks.
Dependency Analysis
By combining with the yum provides command, complete file-to-package mapping relationships can be constructed. This is particularly useful for resolving dependency conflicts or finding the source of specific files.
System Migration and Backup
When performing system migration or developing backup strategies, understanding files contained in each package helps create more precise backup plans, avoiding omission of important configuration or data files.
Best Practice Recommendations
Based on different usage scenarios, the following best practices are recommended:
For daily queries of installed package contents, prioritize rpm -ql due to its lack of additional dependencies and high execution efficiency.
When needing to query contents of available packages in repositories, repoquery -l is the best choice, especially when planning software installation or assessing package impact.
In newer Fedora or RHEL 8+ systems, using DNF and its repoquery subcommand is advised for better performance and future compatibility.
When encountering empty query results, first try adding the --installed flag. If the issue persists, verify the package name correctness and repository configuration status.
Conclusion
Through various tools provided by the YUM ecosystem, Linux system administrators can flexibly query package content information. repoquery, as a key component of yum-utils, fills the functional gap in YUM for package content queries, offering a more convenient solution than traditional RPM commands. With DNF's adoption, related query functionalities have been inherited and enhanced. Mastering these tools will significantly improve the efficiency and accuracy of Linux system administration.