RPM SPEC files know about package versions in both Requires: and Provides: tags, so inside a SPEC file it's easy to build proper dependency even with mangled names (e.g. to avoid conflicts and allow multiple versions of packages)As an example package foo provides updated version:Name: fooxProvides: foo = 2andName: bar5Requires: foo >= 2works quite well - yum will not install bar5 unless foox is also installed.My question - how can I query which package provides foo = 2 from command line?From the man page of rpm it appears that--whatprovides CAPABILITYQuery all packages that provide the CAPABILITY capability. --providesList capabilities this package provides.Would've sufficed.  I can rpm -q --provides <package name> and see the version.  I can even rpm -q --qf %{VERSION} <package name> and get only the version.  However, I can't rpm -q --whatprovides on the name and version to get the actual package name.I have also tried rpm -q --provides foo but I only get the original foo = 1, even though foox is installed and provides foo = 2.what I would like is the following magic:$ rpm -q --whatprovides foo = 2$ foox
How to query which RPM package provides a specific version
rpm
That's close:rpm -q --whatprovides foo = 2but it does not accept a version.  To get that, go back a step and format the output fromrpm -q --whatprovides foolike this:rpm -q --queryformat %{VERSION}:%{NAME}\n --whatprovides fooand filter the result by grep (to select your 2), and then through sed, to remove the extra version followed by a colon:grep -E '/^2:/' | sed -e 's/^[^:]*://'That gives just the package name.  In practice, you would want the version, release and architecture to install the correct dependency.For reference: 5.2.5. Determining which package provides a certain capability (Fedora RPM Guide)Regarding OP's comment that awk would be simpler:awk -F: '{ if ($1 == 2) print $2}'I agree (but from habit working on configure scripts, use awk second to grep/sed, since it is a little less portable).  However, if one wanted to check for packages with versions greater than or equal to a given value, awk would definitely be much simpler, e.g.,awk -F: '{ if ($1 >= 2) print $2}'That occurred to me this morning after I'd already left.  But that type of comparison is probably more common in spec-files than exact matches.  Also, quoting the 2 may force awk to treat it as a string rather than a number.  That would not match version 2.0, but leaving it unquoted — and numeric — would let it match.@dave-thompson-085 pointed out that enclosing the comparison within the action is unnecessary.  That is, the part within { and } in the preceding is an action, for all lines (since no pattern is given). Quoting from mawk's manual page:An AWK program is a sequence of pattern {action} pairs and  user  function definitions.and then   A pattern can be:          BEGIN          END          expression          expression , expressionAn expression might be a regular expression, but could also be an comparison.  His suggested improvement isawk -F: '$1>=2{print $2}'