実行するコマンドのバイナリがどこに格納されているか調べたい時は、which
コマンドを実行します。
構文
which コマンド名 オプション
実行例
dnfの場所を調べる
[yoyo@AL ~]$ which dnf
/usr/bin/dnf
dnfは/usr/bin
にある事が分かりました。
sshdの場所を調べる
[yoyo@AL ~]$ which sshd
/usr/sbin/sshd
sshdは/usr/sbin
にある事が分かりました。
複数コマンドを同時に調べる
[yoyo@AL ~]$ which dnf sshd
/usr/bin/dnf
/usr/sbin/sshd
このように複数コマンドを同時に調べる事もできます。
コマンドがない場合
[yoyo@AL ~]$ which python
/usr/bin/which: no python in (/home/yoyo/.local/bin:/home/yoyo/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin)
実行コマンドがインストールされていない場合はこのように表示されます。
バージョンを確認する
[yoyo@AL ~]$ which -v
GNU which v2.21, Copyright (C) 1999 - 2015 Carlo Wood.
GNU which comes with ABSOLUTELY NO WARRANTY;
This program is free software; your freedom to use, change
and distribute this program is protected by the GPL.
インストール
環境によってはそもそもwhich
コマンドが入っていない事があります。
そんな時はdnf provides
で調べてインストールします。
パッケージの調査
[yoyo@AL ~]$ dnf provides which
which-2.21-29.el9.x86_64 : Displays where a particular program in your path is located
Repo : @System
Matched from:
Provide : which = 2.21-29.el9
which-2.21-29.el9.x86_64 : Displays where a particular program in your path is located
Repo : baseos
Matched from:
Provide : which = 2.21-29.el9
which
そのままのパッケージ名で提供されているみたいです。
インストール
dnf install which -y
その他の使い方
which
の基本的な使い方は以上ですが、細かなオプションがいくつかあります。
一度man which
やwhich --help
で確認しておくと良いでしょう。