mac コマンドの種類を取得する

  • 作成日 2022.11.15
  • mac
mac コマンドの種類を取得する

macで、コマンドを使用して、コマンドの種類を取得する手順を記述してます。「 type 」で種類を確認したいコマンドを指定します。PATHを取得する場合はオプション「-p」を使用します。

環境

  • OS macOS Monterey
  • SHELL /bin/zsh

コマンドの種類を取得

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

% type cat

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

% type cd

<出力結果>
cd is a shell builtin

% type ls

<出力結果>
ls is /bin/ls

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

% type -a cd

<出力結果>
cd is a shell builtin
cd is /usr/bin/cd

PATHを取得

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

% type -p cat

<出力結果>
/bin/cat

% type -p httpd

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

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

% whereis cat

<出力結果>
/bin/cat

% whereis httpd

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