开发者

how to get list of rpm packages installed in the system

开发者 https://www.devze.com 2023-04-12 04:09 出处:网络
how to get list of all rpm packages installed on Linux using Perl. any help is appreci开发者_如何学Cated.I guess you can always use the rpm command:

how to get list of all rpm packages installed on Linux using Perl. any help is appreci开发者_如何学Cated.


I guess you can always use the rpm command:

$ rpm --query --all  --qf "%-30{NAME} - %{VERSION}\n"

You can then use this in a wide variety of ways:

use autodie;
open my $RPM_FH, "-|", qq(rpm --query --all --qf "%-30{NAME} - %{VERSION}\n");
my @rpmLines = <$RPM_FH>;
close $RPM_FH;

Or:

 my @rpmLines = qx(rpm --query --all --qf "%-30{NAME} - %{VERSION}\n");

I've also found RPM::Database which would be a more Perlish way of doing things. This package ties the RPM database to a hash:

use RPM::Database;

tie %RPM, "RPM::Database" or die "$RPM::err";

for (sort keys %RPM)
{
    ...
}

I have never used it, so I'm not sure exactly how it would work. For example, I assume that the value of each hash entry is some sort of database object. For example, I would assume that it would be important to know the version number and the files in your RPM package, and there must be someway this information can be pulled, but I didn't see anything in RPM::Database or in RPM::HEader. Play around with it. You can use Data::Dumper to help explore the objects returned.

WARNING: Use Data::Dumper to help explore the information in the objects, and the classes. Don't use it to figure out how to pull the information directly from the objects. Use the correct methods and classes.


The easiest way is probably to shell out to the rpm program.

chomp(my @rpms = `rpm -qa`);


Depending on how to interpret your question, the correct answer can be:

rpm -qR perl
0

精彩评论

暂无评论...
验证码 换一张
取 消