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 Comments

OMARMarch 2nd, 2011 at 19:43

YOUR HELP WAS VERY VERY USEFUL

THANKS A LOT .. SERIOUSLY

GlennAugust 12th, 2011 at 21:53

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 comment

Your comment