Thursday, January 6, 2022

[SOLVED] yum list installed | wc -l Vs. rpm -qa | wc -l

Issue

This goes back to very basics, however I am confused on how.

We know yum is a repository manager that is based on rpm the package manager in RPM based systems, like Fedora.

Having said that, I thought these two commands can be used to produce the same output (in that sense I guess yum commands are the wrapper for rpm commands), however I was just proved to be wrong. Please consider the following example:

[myuser@localhost ~] yum list installed | wc -l
1627 

[myuser@localhost ~] rpm -qa | wc -l
1640

These two commands produce different result, that I believed should not. I would be grateful if anyone can explain the scenario behind it.

PS: I am on Fedora 28


Solution

they don't produce exactly the same output... yum list installed also prints some headers:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * epel: ftp.nluug.nl
epel
Installed Packages

furthermore some packages can be printed on multiple lines with their version number and repository.

If you start counting those lines, then the count won't be correct. Note that the output of yum list installed also reprints output on the same line; not sure how wc deals with that...

The count of rpm -qa | wc -l however is biased also; because it contains the pubkey entries; which are not real packages.

Take a look at this answer where there are many details on these outputs: https://unix.stackexchange.com/a/330599/64031



Answered By - Chris Maes