RPM query output formatting (print your arch!)

By default, rpm doesn’t print a package’s arch when you query it with rpm -q. On a x86_64 system, you’ll see something like that:

[root@earth ~]# rpm -q libselinux
libselinux-1.33.4-5.el5
libselinux-1.33.4-5.el5

not very usefult, is it ?

To make rpm print the arch, well it’s easy, just use the –qf (–queryformat) option, with the ARCH tag:

rpm -qa --qf "%{NAME} %{ARCH}\n"

To know all the printable tags:

rpm --querytags

For example, this will give you something similar to rpm -q, but with the arch at the end of the line:

rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE} %{ARCH}\n"
[root@earth ~]# rpm -q --qf "%{NAME}-%{VERSION}-%{RELEASE} %{ARCH}\n" libselinux 
libselinux-1.33.4-5.el5 x86_64
libselinux-1.33.4-5.el5 i386

2 thoughts on “RPM query output formatting (print your arch!)

  1. Glenn

    I slightly more useful verison of that command would be to add a period between %{RELEASE} and %{ARCH}.

    rpm -qa –qf “%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n”

    Then you can cut and past the output into a command that acts only one of the versions. for example, you want to remove the i386 version only:

    rpm -e libselinux-1.33.4-5.el5.i386

Leave a Reply

Your email address will not be published.