vipin batra
vipin batra

Reputation: 29

Package version in Linux (Centos)?

I need to retrieve the package versions for all packages installed on my Linux (Centos) host. rpm -qa gives me list of all installed packages. I understand that rpm -qi "package name" gives me package information. I tried doing a grep for package version from there and pick the version for display - but this creates a problem for some packages as some text gets appended for some of the packages along with the version. Below is my code line:- rpm -qi "package name"| grep -w Version | awk '{print $3}'

Is there any other way to get the package version - probably from package name itself? We need a report with package names in one column and versions in second column. Please help.

Thanks.

Upvotes: 0

Views: 400

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 80931

You can tell rpm how to construct its output using the --qf flag. It takes a format string as an argument.

So something like the following should get you what you want.

rt=$(ip route get 8.8.8.8 | awk 'NR==1 {print $NF}')
rpm -qa --qf "$tdydate,$rt,%{name},%{version}\n"

Upvotes: 1

Related Questions