Linux コマンドのタイプを取得する

Linux コマンドのタイプを取得する

Linuxで、コマンドのタイプを取得する手順を記述してます。

環境

  • OS Rocky Linux release 8.4 (Green Obsidian)

コマンドのタイプを取得

コマンドのタイプを取得するには、「 type 」コマンドを使用します。

$ type cat

<出力結果>
cat はハッシュされています (/usr/bin/cat)

$ type cd

<出力結果>
cd はシェル組み込み関数です

$ type ls

<出力結果>
ls は `ls --color=auto' のエイリアスです

オプション「-a」を使用すれば、全てのtypeが取得できます。

$ type -a ls

<出力結果>
ls は `ls --color=auto' のエイリアスです
ls は /usr/bin/ls です

$ type -a cd

<出力結果>
cd はシェル組み込み関数です
cd は /usr/bin/cd です

PATHを取得

pathのみを取得する場合は、オプション「-p」を使用します。

$ type -p cat

<出力結果>
/usr/bin/cat

$ type -p httpd

<出力結果>
/usr/sbin/httpd

「whereis」でも同様のことが可能です。

$ whereis cat

<出力結果>
cat: /usr/bin/cat /usr/share/man/man1/cat.1.gz /usr/share/man/man1p/cat.1p.gz

$ whereis httpd

<出力結果>
httpd: /usr/sbin/httpd /usr/lib64/httpd /etc/httpd /usr/share/httpd /usr/share/man/man8/httpd.8.gz