Different list of installed packages reported by rpm compared to yum
yum list installed has 930 lines while rpm -qa has 895 lines, what might be the difference ?
This is likely just formatting differences. yum list will do a bunch of clever wrapping to your terminal size.
What you probably want to do is use:
# Run this on the master server
yum-debug-dump
# Run this on the new server, with the input from the above.
yum-debug-restore
what might be the difference ?
The primary reason for the differing number of lines is that the output produced by yum
is formatted so that each field lines up vertically (regardless of the length of the package name and/or version number). It does this by using two lines for listing such packages and padding the second line with space characters to line up the fields correctly. The following output (from a CentOS 6 box) shows that two lines are used to list the device-mapper-persistent-data.x86_64
package:
device-mapper-libs.x86_64 1.02.95-3.el6_7.4 @clearos-verified-updates
device-mapper-persistent-data.x86_64
0.3.2-1.el6 @clearos
dhclient.x86_64 12:4.1.1-49.P1.v6 @clearos-verified-updates
However, this is not the only reason and it can be seen by massaging the output of the two commands before comparing them:
For the output of rpm
command:
Sort it so that packages beginning with an upper case letter appear before those with lower case:
rpm -qa | LC_ALL=C sort
Use a
sed
command to remove the package version numbers:rpm -qa | LC_ALL=C sort r | sed 's/-[^-]*-[^-]*$//' >| installed.rpm
For the output of the yum
command:
Remove the first two header lines (
Loaded plugins
andInstalled Packages
):Loaded plugins: etckeeper, fastestmirror Installed Packages
We can use
sed
for this:yum list installed | sed '1,2d;'
We can also use
sed
to remove all the lines that are continuations of a package listing (these lines begin with a number of spaces so that all the package versions line up).yum list installed | sed '1,2d;/^ /d;s/\..*//' >| installed.yum
Now, we can use the diff
command to compare the output of the two files. Here’s the results from the CentOS 6 box:
# diff installed.{rpm,yum}
239,243d238
< gpg-pubkey
< gpg-pubkey
< gpg-pubkey
< gpg-pubkey
< gpg-pubkey
Conclusion
This shows that rpm -qa
also includes package listings for the public keys that are trusted to sign packages while the yum
command omits these packages.