Unbeknownst to many, rpm supports random printf() style query strings via the –qf option. List all available tags with “rpm –querytags” and display them with “rpm -q –qf ‘%{QUERYVARIABLE}’. On some versions of rpm, you need to place multiple variables inside brackets ( [] ) to display them all properly.
Use the ARCH and NAME tags along with sort to display a list of all packages and the architecture they were built for:
$ rpm -qa --qf '[%{ARCH} %{NAME}\n]' | sort i386 zip i386 zlib i686 glibc i686 kernel i686 kernel-smp i686 openssl noarch basesystem noarch htmlview noarch hwdata noarch man-pages ...
Say you want to look at the licenses of every package installed on your system except gpl and bsd code. Rpm makes this very easy
$ rpm -qa --qf '[%{LICENSE} %{NAME}\n]' | egrep -v '(GPL|BSD)' public domain setup public domain basesystem distributable ncurses freeware vim-minimal Freely Distributable cyrus-sasl XFree86 redhat-menus distributable symlinks distributable zip Artistic perl-RPM2 distributable perl-XML-Encoding Public Domain expect Artistic perl-XML-Simple ...
A fairly complex example script showing the power to rpm querystrings and how they can be useful in the real world is available here under the terms of the GNU GPLv2. It querys the rpm database using the verify function (-V). It shows you files that have changed permissions or ownership and optionally allows you to fix them.
No Comments
Leave a Comment
trackback address