LoginSignup
1
0

実行するコマンドのバイナリがどこに格納されているか調べたい時は、whichコマンドを実行します。

構文

which コマンド名 オプション

実行例

dnfの場所を調べる

[yoyo@AL ~]$ which dnf
/usr/bin/dnf

dnfは/usr/binにある事が分かりました。

sshdの場所を調べる

[yoyo@AL ~]$ which sshd
/usr/sbin/sshd

dnfは/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 whichwhich --helpで確認しておくと良いでしょう。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0