[plug] rpm command

Russell Keith-Magee Russell.Magee at calytrix.com
Wed Mar 6 08:21:37 WST 2002


> I need to know how to query a group of packages that may contain a file
> (libdb-3.1.so).  I used the following to no prevail:
>
> rpm -qp lib*|grep libdb-3.1.so
>
> Does anyone know the correct command?

Well, theres always more than one way to skin that cat... :-)

FYI, rpm -qp lib* gives pretty much the same result as ls lib*.rpm, but
without the rpm suffix on each file name. Not really useful for your
purposes.

The simplest variant of your command that will produce a result is:

rpm -qlp lib*  | grep libdb-3.1.so

rpm -qlp lists the contents of packages; grep filters out appropriate
matches. However, this will only tell you IF libdb exists, not which rpm has
it. Performing a grep -l doesn't help, as grep will identify the source as
(standard input), not the original rpm file.

So, try this one.

for i in `ls lib*.rpm`; do
	if [ ! -z `rpm -qlp $i | grep libdb-3.1.so` ]; then
		echo $i
	fi
done

This work on bash; ymmv if you use another shell. It can also be typed on a
single line if you put semicolons after the echo and fi lines.

This iterates through each lib*.rpm file in the directory, rpm -qlp's each
one to get file contents, checks each file contents for libdb-3.1.so, and if
the result is not an empty string (that's the [ ! -z ] part) it outputs the
file name.

There may be an easier way, but my 8-in-the-morning-and-no-coffee-yet addled
mind can't think of one. :-)

HTH,
Russ

********************************************
Russell Keith-Magee
Software Engineer
Calytrix Technologies
Unit 9, EIR Building, Technology Park
PO Box 1173, BENTLEY 6982, Western Australia

Tel: +61 8 9362 5300
Fax: +61 8 9362 5400
Mobile: 0408 928 379



More information about the plug mailing list