Merge pull request #406 from geekpi/master

[Translating] Options in Linux RPM Command to Query Packages
This commit is contained in:
vito-L 2013-11-12 23:45:36 -08:00
commit e310d7a22f
2 changed files with 109 additions and 108 deletions

View File

@ -0,0 +1,109 @@
用来查询安装包的Linux RPM选项
================================================================================
RPM是RedHat的包管理器用来安装/卸载/升级和查询基于RedHta Linux的安装包。RHEL和基于它的系统使用rpm命令这么做。以下是一些例子来演示rpm的查询和展示你可以用不同的方法来查询rpm数据库和还原配置文件。
我已经包含了SSH包在示例命令中。
### 查询RPM数据库和包 ###
**1、 在整个RPM数据库中查询使用下面的命令**
# rpm -qa
plymouth-0.8.3-27.el6.x86_64
pciutils-libs-3.1.10-2.el6.i686
netcf-libs-0.1.9-3.el6.x86_64
..
..
Output Truncated
**2、 你可以确定在上面的例子中有哪些SSH包已经安装通过grep命令**
# rpm -qa |grep ssh
libssh2-1.4.2-1.el6.x86_64
openssh-askpass-5.3p1-84.1.el6.x86_64
libssh2-1.4.2-1.el6.i686
openssh-server-5.3p1-84.1.el6.x86_64
openssh-clients-5.3p1-84.1.el6.x86_64
openssh-5.3p1-84.1.el6.x86_64
输出显示了一些关于SSH的包但是你仍需确定哪个包真正安装了SSH。为了更近一步请看下面的示例。
**3、 检查已安装的SSH包 a) 通过sshd守护进程 b) 通过它的配置文件**
# rpm -qf /etc/init.d/sshd
openssh-server-5.3p1-84.1.el6.x86_64
# rpm -qf /etc/ssh/sshd_config
openssh-server-5.3p1-84.1.el6.x86_64
如你所见ssh是通过openssh-server-5.3p1-84.1.el6.x86_64包安装的你可以在守护进程或者配置文件中使用rpm -qf命令。两者都会输出包从哪里安装。
**4、 现在你有了包名你可能想要探索更多并想要知道包中包含了哪些不同的文件。这种情况下使用rpm -ql命令**
# rpm -ql openssh-server-5.3p1-84.1.el6.x86_64
/etc/pam.d/ssh-keycat
/etc/pam.d/sshd
/etc/rc.d/init.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
/usr/libexec/openssh/sftp-server
/usr/libexec/openssh/ssh-keycat
/usr/sbin/.sshd.hmac
/usr/sbin/sshd
/usr/share/doc/openssh-server-5.3p1
/usr/share/doc/openssh-server-5.3p1/HOWTO.ssh-keycat
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz
/var/empty/sshd
上面的输出显示了所有该包在系统中安装的文件。现在让我们更进一步,我们只想要看到该包提供的配置文件和文档。
**5、 只显示配置文件使用rpm -qc命令**
# rpm -qc openssh-server-5.3p1-84.1.el6.x86_64
/etc/pam.d/ssh-keycat
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
**6、 只列出文件使用rpm -qd命令**
# rpm -qd openssh-server-5.3p1-84.1.el6.x86_64
/usr/share/doc/openssh-server-5.3p1/HOWTO.ssh-keycat
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz
考虑一种情况你想要配置一个服务,但是你不知道哪里找到配置文件。举例来说,考虑上面的例子:使用**rpm -qf rpm -qf /etc/init.d/sshd**来找出 **/etc/ssh/sshd_config**这个文件源于哪个包。这应该会给你显示**openssh-server-5.3p1-84.1.el6.x86_64**包。使用**rpm -ql openssh-server-5.3p1-84.1.el6.x86_64**来显示包中所含的所有文件。如你所见,许多文件名显示了出来,但是输出并不非常有用。
现在使用**rpm -qc openssh-server-5.3p1-84.1.el6.x86_64** 来只显示这个包的配置文件。这只会显示4个文件并给出了[/etc/ssh/sshd_config file][1]的绝对路径来开始配置服务。
**7、 从PRM包还原配置文件而不重新安装包。**
如果由于一些原因文件损坏或者从系统中删除了,你可以以**rpm -qf**开头来找出文件存在于哪个包。接下来使用**rpm2cpio | cpio -idmv**来从包中解压出文件。考虑ssh的例子。
假设**/etc/ssh/sshd_config**文件已经删除并且你不希望重装ssh按以下步骤来还原文件。
* 使用rpm -qf /etc/init.d/sshd 这个命令会显示文件来自于openssh-server-5.3p1-84.1.el6.x86_64包。
* 从它的源中下载Openssh的rpm包。
* 复制openssh-server-5.3p1-84.1.el6.x86_64包到/tmp目录或者其他任何你选择的目录。
* 使用rpm2cpio |cpio -idmv解压包。
上面步骤中你使用的命令会在/tmp下面创建一个子目录。你现在可以复制到它的原始目录。
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-command/rpm-command-query/
译者:[geekpi](https://github.com/geekpi) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://www.linoxide.com/how-tos/disable-ssh-direct-login/

View File

@ -1,108 +0,0 @@
Options in Linux RPM Command to Query Packages
================================================================================
RPM is RedHat Package Manager, used to install/remove/update and query the packages in Red Hat based linux. RHEL and the systems based on it uses rpm command to do that. The following example demonstrates the use of rpm query feature and shows different ways you can query rpm database and restore configuration file.
I have included the SSH package to in the example commands.
### Query RPM Database and Packages ###
**1、 To query the whole RPM database, use the following command.**
# rpm -qa
plymouth-0.8.3-27.el6.x86_64
pciutils-libs-3.1.10-2.el6.i686
netcf-libs-0.1.9-3.el6.x86_64
..
..
Output Truncated
**2、 You can identify the package from which SSH is installed by using grep on the above example.**
# rpm -qa |grep ssh
libssh2-1.4.2-1.el6.x86_64
openssh-askpass-5.3p1-84.1.el6.x86_64
libssh2-1.4.2-1.el6.i686
openssh-server-5.3p1-84.1.el6.x86_64
openssh-clients-5.3p1-84.1.el6.x86_64
openssh-5.3p1-84.1.el6.x86_64
The output shows other packages related to ssh but you have to still identify that which package is actually installing SSH. To further break it down see the next example.
**3、 Check the installed package of SSH a) from sshd daemon b) from its configuration file.**
# rpm -qf /etc/init.d/sshd
openssh-server-5.3p1-84.1.el6.x86_64
# rpm -qf /etc/ssh/sshd_config
openssh-server-5.3p1-84.1.el6.x86_64
As you can see the ssh is installed from the openssh-server-5.3p1-84.1.el6.x86_64 package. You can use rpm -qf command both on daemon and a configuration file. Both will output the package it is installed from.
**4、 Now that you have the package name, you may want to explore more on it and want to know what are the various files this package contains. For that use rpm -ql command.**
# rpm -ql openssh-server-5.3p1-84.1.el6.x86_64
/etc/pam.d/ssh-keycat
/etc/pam.d/sshd
/etc/rc.d/init.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
/usr/libexec/openssh/sftp-server
/usr/libexec/openssh/ssh-keycat
/usr/sbin/.sshd.hmac
/usr/sbin/sshd
/usr/share/doc/openssh-server-5.3p1
/usr/share/doc/openssh-server-5.3p1/HOWTO.ssh-keycat
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz
/var/empty/sshd
he above output is showing all the files that this package installed on the system. Now lets even break it down and we only want to see the configuration files and document files supplied with this package.
**5、 To list only the configuration files use the rpm -qc command.**
# rpm -qc openssh-server-5.3p1-84.1.el6.x86_64
/etc/pam.d/ssh-keycat
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
**6、 To list only documentation files use rpm -qd command**
# rpm -qd openssh-server-5.3p1-84.1.el6.x86_64
/usr/share/doc/openssh-server-5.3p1/HOWTO.ssh-keycat
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz
Consider a situation in which you want to configure a service, but you dont know where to find the configuration files. As an example, Consider the above example: Use **rpm -qf rpm -qf /etc/init.d/sshd** to find out from what package the **/etc/ssh/sshd_config** file originated. It should show you the **openssh-server-5.3p1-84.1.el6.x86_64** package. Use **rpm -ql openssh-server-5.3p1-84.1.el6.x86_64** to show a list of all the files in this package. As you can see, the names of many files are displayed, but the output is not very useful.
Now use **rpm -qc openssh-server-5.3p1-84.1.el6.x86_64** to show just the configuration files used by this package. This shows a list of four files only and gives you the absolute path of [/etc/ssh/sshd_config file][1] to start configuring the service.
**7、 Restore configuration file from RPM Package, without reinstalling a package.**
If for some reason a file has been damaged or got deleted from system, you can start with the **rpm -qf** query option to find out from what package the file originated. Next use **rpm2cpio | cpio -idmv** to extract the files from the package. Consider the ssh example:
Assuming that the **/etc/ssh/sshd_config** file has been deleted and you may not want to reinstall ssh, Restore the file using the steps below.
* Use rpm -qf /etc/init.d/sshd This command shows that the file comes from the openssh-server-5.3p1-84.1.el6.x86_64 Package.
* Download the Openssh rpm from its source
* Copy openssh-server-5.3p1-84.1.el6.x86_64 package file to /tmp directory or any other directory of your choice.
* Use rpm2cpio |cpio -idmv to extract the package.
The command you used in the above step created a few subdirectories in /tmp. You can now copy it to its original location.
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-command/rpm-command-query/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://www.linoxide.com/how-tos/disable-ssh-direct-login/