TipsAndTricks/UsingRPM: Difference between revisions
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
First in order to perform a query, you want to tell the system to go into query mode: | First in order to perform a query, you want to tell the system to go into query mode: | ||
''rpm -q'' | ''rpm -q'' | ||
Line 10: | Line 10: | ||
To query a single package that has been installed into the database, just add the package name, such as: | To query a single package that has been installed into the database, just add the package name, such as: | ||
''rpm -q bash'' | ''rpm -q bash'' | ||
To query all of the installed packages in the system, add the '-a' option, such as: | To query all of the installed packages in the system, add the '-a' option, such as: | ||
''rpm -q -a'' | ''rpm -q -a'' | ||
To query a single package that is not yet installed, add '-p <package name>' | To query a single package that is not yet installed, add '-p <package name>' | ||
''rpm -q -p bash-3.0-r3.i386.rpm'' | ''rpm -q -p bash-3.0-r3.i386.rpm'' | ||
To query multiple packages, just list the packages after the -p: | To query multiple packages, just list the packages after the -p: | ||
''rpm -q -p bash-3.0-r3.i386.rpm libc6-7-r3.i386.rpm'' | ''rpm -q -p bash-3.0-r3.i386.rpm libc6-7-r3.i386.rpm'' | ||
You can include lists of packages instead: | You can include lists of packages instead: | ||
''echo "bash-3.0-r3.i386.rpm" > mymanifest.txt | ''echo "bash-3.0-r3.i386.rpm" > mymanifest.txt'' | ||
echo "libc6-7-r3.i386.rpm" >> mymanifest.txt | ''echo "libc6-7-r3.i386.rpm" >> mymanifest.txt'' | ||
rpm -q -p mymanifest.txt | ''rpm -q -p mymanifest.txt'' | ||
'' | |||
(Note: there is a minimum size of the file for RPM to determine this is a manifest file. So it's recommended if this is used in script to always include a header that says something like "# This is a manifest file". | (Note: there is a minimum size of the file for RPM to determine this is a manifest file. So it's recommended if this is used in script to always include a header that says something like "# This is a manifest file". | ||
Line 38: | Line 37: | ||
In order to select the exact items you want to query, you want to use the '--queryformat' (or '--qf') to specify a format. Such as: | In order to select the exact items you want to query, you want to use the '--queryformat' (or '--qf') to specify a format. Such as: | ||
''rpm -q -p mymanifest.txt --qf "[%{NAME}\n]"'' | ''rpm -q -p mymanifest.txt --qf "[%{NAME}\n]"'' | ||
The above duplicates the default. The special characters or parts being used are: | The above duplicates the default. The special characters or parts being used are: | ||
Line 52: | Line 51: | ||
For instance, the typical, 'rpm -q bash --requires' is actually implemented as: | For instance, the typical, 'rpm -q bash --requires' is actually implemented as: | ||
''rpm -q bash --qf "[%|VERBOSE?{%{REQUIREFLAGS:deptype}: }:{}|%{REQUIRENEVRS}\n]"'' | ''rpm -q bash --qf "[%|VERBOSE?{%{REQUIREFLAGS:deptype}: }:{}|%{REQUIRENEVRS}\n]"'' | ||
The above indicate that based on the value 'VERBOSE', either %{REQUIREFLAGS:deptype} followed by either {} | %{REQUIRENEVRS}. | The above indicate that based on the value 'VERBOSE', either %{REQUIREFLAGS:deptype} followed by either {} | %{REQUIRENEVRS}. | ||
Line 62: | Line 61: | ||
Another popular example is how to export the whole DB to XML: | Another popular example is how to export the whole DB to XML: | ||
''rpm -qa --qf "[%{*:xml}\n]"'' | ''rpm -qa --qf "[%{*:xml}\n]"'' | ||
The '*' says to not only query the main thing, but also iterate over the matching entries (all of them), with the :xml indicating to dump the contents in XML format. | The '*' says to not only query the main thing, but also iterate over the matching entries (all of them), with the :xml indicating to dump the contents in XML format. |
Latest revision as of 17:52, 15 March 2018
The RPM command allows for a number of query operations. The format of the query operations can be used for a number things, such as debugging a package or even exporting information into another format, such as XML.
First in order to perform a query, you want to tell the system to go into query mode:
rpm -q
You then need to add the option to tell it WHAT to query:
To query a single package that has been installed into the database, just add the package name, such as:
rpm -q bash
To query all of the installed packages in the system, add the '-a' option, such as:
rpm -q -a
To query a single package that is not yet installed, add '-p <package name>'
rpm -q -p bash-3.0-r3.i386.rpm
To query multiple packages, just list the packages after the -p:
rpm -q -p bash-3.0-r3.i386.rpm libc6-7-r3.i386.rpm
You can include lists of packages instead:
echo "bash-3.0-r3.i386.rpm" > mymanifest.txt echo "libc6-7-r3.i386.rpm" >> mymanifest.txt rpm -q -p mymanifest.txt
(Note: there is a minimum size of the file for RPM to determine this is a manifest file. So it's recommended if this is used in script to always include a header that says something like "# This is a manifest file".
The above operations simply control the 'what', by default the system will just print the package name. (Some versions will print the name and package architecture.)
In order to select the exact items you want to query, you want to use the '--queryformat' (or '--qf') to specify a format. Such as:
rpm -q -p mymanifest.txt --qf "[%{NAME}\n]"
The above duplicates the default. The special characters or parts being used are:
[ ] - this indicates that it should be applied on each package or item (if the item being queried is an iterator, like a filelist.) Including '\n' inside of the brackets means adding a line feed at the end of every item that is queried. %{...} -- this is how you specify the exact field to be queried. To get a list of valid options, you can run: 'rpm --querytags'.
The format of %{...} also allows for select 'type' conversions. Some of the valid types are: octal, shescape, deptype, pgpsig, day, date, and others.
For instance, the typical, 'rpm -q bash --requires' is actually implemented as:
rpm -q bash --qf "[%|VERBOSE?{%{REQUIREFLAGS:deptype}: }:{}|%{REQUIRENEVRS}\n]"
The above indicate that based on the value 'VERBOSE', either %{REQUIREFLAGS:deptype} followed by either {} | %{REQUIRENEVRS}.
| ? and other special operators exist to permit you to do some basic boolean cases. See: /usr/lib/rpm/rpmpopt-* for a bunch of examples.
Another popular example is how to export the whole DB to XML:
rpm -qa --qf "[%{*:xml}\n]"
The '*' says to not only query the main thing, but also iterate over the matching entries (all of them), with the :xml indicating to dump the contents in XML format.