ヒトリ歩き

愚痴とかいろいろ書きます

知っておいた方がいいrpmコマンドのオプション

OSのバージョンアップでパッケージやコマンドの調査を行う際に、どのコマンドがどのパッケージに含まれているのか分からなかったりします。
そんな時に、rpmコマンドを使えば、コマンドがどのパッケージに含まれているのか調べることができます。
実際に調べる際にこれ早く知ってればよかったと思ったrpmコマンドのオプションを紹介します。

ファイルからパッケージを探す

rpm -qf <ファイル名>で、指定したファイル名が含まれるパッケージを出力します。 /usr/sbin/nginxがどのパッケージに含まれているのか探す場合は、下記のように実行します。

$ rpm -qf /usr/sbin/nginx
nginx-1.16.1-1.el7.ngx.x86_64

パッケージの情報を表示する

rpm -qi <パッケージ名> で、パッケージの情報を表示することができます。 nginxパッケージを指定すると下記のように表示されます。 パッケージに関する具体的な情報が知りたい場合に、表示されているURLにアクセスして情報収集したりします。

$ rpm -qi nginx-1.16.1-1.el7.ngx.x86_64
Name        : nginx
Epoch       : 1
Version     : 1.16.1
Release     : 1.el7.ngx
Architecture: x86_64
Install Date: 20200417132751秒
Group       : System Environment/Daemons
Size        : 2811768
License     : 2-clause BSD-like license
Signature   : RSA/SHA1, 20190813161659秒, Key ID abf5bd827bd9bf62
Source RPM  : nginx-1.16.1-1.el7.ngx.src.rpm
Build Date  : 20190813150433秒
Build Host  : centos74-amd64-builder-builder.gnt.nginx.com
Relocations : (not relocatable)
Vendor      : Nginx, Inc.
URL         : http://nginx.org/
Summary     : High performance web server
Description :
nginx [engine x] is an HTTP and reverse proxy server, as well as
a mail proxy server.

パッケージに含まれているファイルの一覧を表示する

rpm -ql <パッケージ名> で、パッケージに含まれるファイル一覧を表示します。 nginxのパッケージに含まれているファイルの一覧を表示してみました。 OSで削除されるパッケージに含まれているコマンドは何かを調べる際に役立ちます。

$ rpm -ql nginx-1.16.1-1.el7.ngx.x86_64
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/modules
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.16.1
/usr/share/doc/nginx-1.16.1/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginx

最後に

rpmコマンドは、パッケージのインストール/アップデート/アンインストールだけでなく、パッケージに関する情報取得が可能です。 OSのバージョンアップや削除されたパッケージに含まれているファイルなどを調べるのに地味に活躍してくれるので、知っていると便利です。 これをもっと早く知っていれば・・・と思うとちょっと泣きたくなりますが、man でコマンドのオプションをしっかりみることも大事だなと改めて思いました。