Home / Community / Wiki / How to query RPMs by Architecture

How to query RPMs by Architecture

Have you ever needed to query your installed RPMs in a Linux system by architecture? In using CentOS, I keep running across 'mixed architecture' systems where yum has helpfully decided to install both 32 and 64 bit versions of many packages. I find this annoying and sloppy, so I prefer to clean it up so that (unless there's a compelling reason to do otherwise) I'm running a 'clean' 64 bit system.

In order to do this, it's helpful to be able to query your RPM database to find out what has gotten installed that is the wrong architecture, and the command to do that is below:

rpm -qa --qf "%{n}-%{v}-%{r}.%{arch}\n"

I often follow this up with the following command:

DO NOT RUN THIS ON A PRODUCTION SYSTEM UNLESS YOU KNOW WHAT YOU'RE DOING!!!

YOU CAN HOSE YOUR INSTALLATION!!!

rpm -e `rpm -qa --qf "%{n}-%{v}-%{r}.%{arch}\n" | grep i[3456]86$`

Good luck and may all your systems be single architecture from here on out!