📄 0057-0059.html
字号:
<HTML>
<HEAD>
<TITLE>Maximum RPM (RPM):Getting Information About Packages:EarthWeb Inc.-</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311054 //-->
<!-- TITLE=Maximum RPM (RPM)//-->
<!-- AUTHOR=Edward Bailey//-->
<!-- PUBLISHER=Macmillan Computer Publishing//-->
<!-- IMPRINT=Sams//-->
<!-- CHAPTER=05 //-->
<!-- PAGES=0053-0078 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0053-0056.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0060-0062.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-57"><P>Page 57</P></A>
<P>Querying based on package labels may seem a bit restrictive. After all, you need to know
the exact name of a package in order to perform a query on it. But there are other ways of
specifying packages.
</P>
<B>
5.2.1.2. -a: Query All Installed Packages
</B>
<P>Want lots of information fast? Using the -a option, you
can query every package installed on your system. Here's an example:
</P>
<!-- CODE //-->
<PRE>
# rpm -qa
ElectricFence-2.0.5-2
ImageMagick-3.7-2
...
tetex-xtexsh-0.3.3-8
lout-3.06-4
#
</PRE>
<!-- END CODE //-->
<P>On a system installed using RPM, the number of packages can easily be 200 or more;
we've deleted most of the output.
</P>
<P>The -a option can produce mountains of output, which makes it a prime candidate for
piping through the many Linux/UNIX commands available. One of the prime candidates would be
a pager such as more, so that the list of installed packages could be viewed
a screenful at a time.
</P>
<P>Another handy command to pipe rpm -qa's output through is
grep. In fact, using grep, it's possible to get around RPM's lack of built-in wildcard processing:
</P>
<!-- CODE SNIP //-->
<PRE>
# rpm -qa | grep -i sysv
SysVinit-2.64-2
#
</PRE>
<!-- END CODE SNIP //-->
<P>In this example, we were able to find the
SysVinit package even though we didn't have the complete package name or capitalization.
</P>
<B>
5.2.1.3. -f <file>: Query the Package Owning
<file>
</B>
<P>How many times have you found a program sitting on your system and wondered what it
does? Well, if the program was installed by RPM as part of a package, it's easy to find out. Simply
use the -f option. For example, you find a strange program called
ls in /bin (okay, it is a contrived example). Wonder what package
installed it? It's as easy as this to find out:
</P>
<!-- CODE SNIP //-->
<PRE>
# rpm -qf /bin/ls
fileutils-3.12-3
#
</PRE>
<!-- END CODE SNIP //-->
<P>If you happen to point RPM to a file it didn't install, you'll get a message similar to the
following:
</P>
<!-- CODE SNIP //-->
<PRE>
# rpm -qf .cshrc
file /home/ed/.cshrc is not owned by any package
#
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-58"><P>Page 58</P></A>
<P>It's possible that you'll get the not owned by any
package message in error. Here's an example of how it can happen:
</P>
<!-- CODE SNIP //-->
<PRE>
# rpm -qf /usr/X11/bin/xterm
file /usr/X11/bin/xterm is not owned by any package
#
</PRE>
<!-- END CODE SNIP //-->
<P>As you can see, we're trying to find out what package
the xterm program is part of. The first example failed, which might lead you to believe that
xterm really isn't owned by any package.
</P>
<P>However, let's look at a directory listing:
</P>
<!-- CODE //-->
<PRE>
# ls -lF /usr
...
lrwxrwxrwx 1 root root 5 May 13 12:46 X11 -> X11R6/
drwxrwxr-x 7 root root 1024 Mar 21 00:21 X11R6/
...
#
</PRE>
<!-- END CODE //-->
<BR>
<P>
<CENTER>
<TABLE BGCOLOR="#FFFF99">
<TR><TD><B>
NOTE
</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
I've truncated the list; normally /usr is quite a bit more crowded than
this.
</BLOCKQUOTE></TD></TR>
</TABLE></CENTER>
</P>
<P>
The key here is the line ending with X11 ->
X11R6/. This is known as a symbolic link, or
symlink. It's a way of referring to a file (here, a directory file) by another name. In this case, if we
used the path /usr/X11 or /usr/X11R6, it shouldn't make a difference. It certainly doesn't make
a difference to programs that simply want access to the file. But it does make a difference to
RPM because RPM doesn't use the filename to access the file. RPM uses the filename as a key
into its database. It would be very difficult, if not impossible, to keep track of all the symlinks on
a system and try every possible path to a file during a query.
</P>
<P>What to do? There are two options:
</P>
<UL>
<LI> Make sure you always specify a path
free of symlinks. This can be pretty tough, though. An alternative approach is to use
namei to track down symlinks:
<!-- CODE //-->
<PRE>
# namei /usr/X11/bin/xterm
f: /usr/X11/bin/xterm
d /
d usr
l X11 -> X11R6
d X11R6
d bin
- xterm
#
</PRE>
<!-- END CODE //-->
<P>
It's pretty easy to see the X11 to
X11R6 symlink. Using this approach you can enter
the nonsymlinked path and get the desired results:
</>
<!-- CODE SNIP //-->
<PRE>
# rpm -qf /usr/X11R6/bin/xterm
XFree86-3.1.2-5
#
</PRE>
<!-- END CODE SNIP //-->
</UL>
<A NAME="PAGENUM-59"><P>Page 59</P></A>
<UL>
<LI> Change your directory to the one holding the file you want to query. Even if you use
a symlinked path to get there, querying the file should
then work as you'd expect:
<!-- CODE SNIP //-->
<PRE>
# cd /usr/X11/bin
# rpm -qf xterm
XFree86-3.1.2-5
#
</PRE>
<!-- END CODE SNIP //-->
</UL>
<P>So if you get a not owned by any package error and you think it might not be true, try one
of these approaches.
</P>
<B>
5.2.1.4. -p <file>: Query a Specific RPM Package File
</B>
<P>Until now, every means of specifying a package to an RPM query focused on packages
that had already been installed. While it's certainly very useful to be able to dredge up
information about packages that are already on your system, what about packages that haven't yet
been installed? The -p option can do that for you.
</P>
<P>One situation where this capability would help occurs when the name of a package file
has been changed. Because the name of the file containing a package has nothing to do with
the name of the package (although by tradition it's nice to name package files consistently), we
can use this option to find out exactly what package a file contains:
</P>
<!-- CODE SNIP //-->
<PRE>
# rpm -qp foo.bar
rpm-2.3-1
#
</PRE>
<!-- END CODE SNIP //-->
<P>With one command, RPM gives you the answer. (On most Linux systems, the
file command can be used to obtain similar information. See Appendix A, "The Format of the RPM
File," for details on how to add this capability to your system's
file command.)
</P>
<P>The -p option can also use URLs to specify package files.
See section 2.2.1 in Chapter 2,
</P>
<P>"Using RPM to Install Packages," for more information on using URLs.
</P>
<P>There's one last trick up -p's sleeve—it can also perform a query by reading a package
from standard input. Here's an example:
</P>
<!-- CODE SNIP //-->
<PRE>
# cat bother-3.5-1.i386.rpm | rpm -qp
- bother-3.5-1
#
</PRE>
<!-- END CODE SNIP //-->
<P>We piped the output of cat into RPM. The dash at the end of the command line directs
RPM to read the package from standard input.
</P>
<B>
5.2.1.5. -g <group>: Query Packages Belonging to Group
<group>
</B>
<P>When a package is built, the package builder must classify the package, grouping it with
other packages that perform similar functions. RPM gives you the ability to query installed
packages based on their groups. For example, there is a group known as Base, which consists of
packages
</P>
<P><CENTER>
<a href="0053-0056.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0060-0062.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -