Bug 149017 - Would like to be able to get version sorted list of install kernels
Would like to be able to get version sorted list of install kernels
Product: Fedora
Classification: Fedora
Component: rpm (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jeff Johnson
Mike McLean
: FutureFeature
Depends On:
  Show dependency treegraph
Reported: 2005-02-17 17:36 EST by Orion Poplawski
Modified: 2007-11-30 17:11 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2005-02-20 13:55:48 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Orion Poplawski 2005-02-17 17:36:28 EST
Description of problem:

It can be hard to determine the version sorted order of installed kernels.  It
would nice to able to obtain a version sorted list with something like:

rpm -q kernel --version-sorted

Is there any order to the listing now?  Insall time?  Man page doesn't appear to

Version-Release number of selected component (if applicable):

Comment 1 James Olin Oden 2005-02-17 21:38:27 EST
I know you want a cli switch but:

   use RPM2;

   my $db = RPM2->open_rpm_db();

   $i = $db->find_by_name_iter("kernel");
   @kernels = $i->expand_iter();
   @kernels = sort(@kernels);
   foreach my $p (@kernels) {
       print $p->as_nvre() . "\n";

Will do the trick.  Its a tiny perl script using RPM2 (perl rpm bindings).  
Its only an example to give you an idea of what you can do.
Comment 2 Orion Poplawski 2005-02-18 13:05:54 EST

@kernels = sort(@kernels);

will do a proper RPM version sort, not just alphanumeric?  There is no idication
in the perl RPM2 documentation that it overrides sort or provides RPM version

I've been using the perl module RPM::VersionSort for this kind of thing but I
was hoping to avoid perl scripts and modules and have:

lastestkernel=`rpm -q kernel --version-sorted | tail -1`

Comment 3 James Olin Oden 2005-02-18 14:12:14 EST
Your right its not documented, but the <=> operator is overloaded to properly
compare EVR's (I know its overloaded because I added that patch (-:).  So yes it
will do what you want (in perl).  The docs in RPM2 could be greatly expanded.

Comment 4 Jeff Johnson 2005-02-20 13:55:48 EST
rpmquery cannot possibly include enough options to satisfy
every possible need and taste.

Extract the information and sort to taste.

Note You need to log in before you can comment on or make changes to this bug.