Wednesday, August 8, 2012

rpm --queryformat


Looking to see what packages are installed and their associated version.  A common command associated with the rpm command is `rpm -qa` which will provide details regarding all of the packages installed on the system.


# rpm -qa | head -n 3
libtermcap-2.0.8-46.1
mgetty-1.1.33-9.fc6
cyrus-sasl-plain-2.1.22-5.el5_4.3

There is another option available that will make processing the same information easier for both the eyes and any script that may be processing this information.  The option in question is the `--queryformat` option.  Briefly described in the man page and http://linux.die.net/man/8/rpm with further discussion available via http://rpm5.org/docs/api/queryformat.html  An example is provided below for reference:

# rpm -qa --queryformat '%{NAME}\n' | head -n 3 
libtermcap
mgetty
cyrus-sasl-plain

# rpm -qa --queryformat '%{NAME} %{VERSION}\n' | head -n 3 
libtermcap 2.0.8
mgetty 1.1.33
cyrus-sasl-plain 2.1.22

Further Examples: 
# rpm -qa --queryformat '%{NAME} %{VERSION} %{RELEASE} 
# rpm -qa --queryformat '%{NAME} %{VERSION} %{RELEASE} %{INSTALLTIME}\n'
# rpm -qa --queryformat '%{NAME} %{INSTALLTIME:date}\n' 

No comments:

Post a Comment