はじめに
timeout
コマンドについてのXの投稿を見て自分の環境下で確認したら実行できたが確認するとmacOS標準のコマンドではなく、Homebrew
でインストールしたコマンドだった。いつインストールしたんだろう?どのパッケージのコマンドなんだろう?と思い、どのパッケージでインストールされたかを調べる過程で分かったことをまとめました。
実行環境
下記の環境で確認しました。
- macOS : 15.5
- Homebrew : 4.5.7-63-gdd04fb5
ターミナル上でsw_vers
、brew --version
コマンドを実行してソフトウェアはのバージョンを確認しました。下記にその実行例を示します。
$ sw_vers
ProductName: macOS
ProductVersion: 15.5
BuildVersion: 24F74
$ brew --version
Homebrew 4.5.7-63-gdd04fb5
Homebrewでインストールしたコマンドのパッケージ名を調べる
brewコマンドで調べる
Homebrewでインストールされたコマンドを含むパッケージ名を調べるオプションはwhich-formula
です。実行結果を以下に示します。
実行結果からcoreutils
とuutils-coreutils
の2つのパッケージに含まれていることが分かります。
$ brew which-formula timeout
coreutils
uutils-coreutils
2つのパッケージの情報をbrew info
コマンドで確認してみます。以下に、コマンドの実行結果を示します。
$ brew info coreutils
==> coreutils: stable 9.7 (bottled), HEAD
GNU File, Shell, and Text utilities
https://www.gnu.org/software/coreutils/
Conflicts with:
b2sum (because both install `b2sum` binaries)
gfold (because both install `gfold` binaries)
idutils (because both install `gid` and `gid.1`)
uutils-coreutils (because coreutils and uutils-coreutils install the same binaries)
Installed <- インストールされている
^^^^^^^^^
/opt/homebrew/Cellar/coreutils/9.7 (465 files, 11.8MB) *
(以下の出力は省略)
$ brew info uutils-coreutils
==> uutils-coreutils: stable 0.1.0 (bottled), HEAD
Cross-platform Rust rewrite of the GNU coreutils
https://uutils.github.io/coreutils/
Conflicts with:
coreutils (because uutils-coreutils and coreutils install the same binaries)
unp (because both install `ucat` binaries)
Not installed <- インストールされていない
^^^^^^^^^^^^^
(以下の出力は省略)
以上の結果から、パッケージcoreutilsはInstalledと表示され、もう一つのパッケージuutils-coreutilsはNot installedと表示されましたのでtimeout
コマンドはcoreutils
でインストールされたことが分かります。
コマンドの保存ディレクトリから判断する
brew which-formula
コマンドでコマンドを含むパッケージ名を調べられますが他の方法でもコマンドのパッケージ名を調べられます。
Homebrew
でインストールされたコマンドの実体は/opt/homebrew/Cellar/パッケージ名/バージョン/bin
にあり、そこへのシンボリックリンクが/opt/homebrew/bin
に作成されます。
コマンドの所在はwhich
コマンドで調べられますが環境変数PATHに保存されるディレクトリが対象なのでHomebrew
でインストールされたコマンドの実体ではなくシンボリックリンクになります。そこで、which
コマンドの出力をls -l
コマンドの引数として与えればリンク先が表示され、所在が分かります。
以下の実行結果からパッケージ名がcoreutils
であることが分かります。
$ ls -l `which timeout`
lrwxr-xr-x 1 sakabe admin 35 4 10 07:06 /opt/homebrew/bin/timeout ->
../Cellar/coreutils/9.7/bin/timeout
^^^^^^^^^
Homebrewでインストールしたコマンド一覧表示
特定のコマンドのパッケージ名を取得できたのでその逆のパッケージによってインストールされたコマンドの一覧はbrew list
コマンドで取得できます。
実行例を以下に示します。コマンド、マニュアルの情報も表示されます。
$ ❯ brew list coreutils
/opt/homebrew/Cellar/coreutils/9.7/bin/b2sum
/opt/homebrew/Cellar/coreutils/9.7/bin/base32
(中略)
/opt/homebrew/Cellar/coreutils/9.7/bin/tac
/opt/homebrew/Cellar/coreutils/9.7/bin/timeout
/opt/homebrew/Cellar/coreutils/9.7/libexec/coreutils/libstdbuf.so
/opt/homebrew/Cellar/coreutils/9.7/libexec/gnubin/ (106 files)
/opt/homebrew/Cellar/coreutils/9.7/libexec/gnuman/ (105 files)
/opt/homebrew/Cellar/coreutils/9.7/sbom.spdx.json
/opt/homebrew/Cellar/coreutils/9.7/share/info/coreutils.info
/opt/homebrew/Cellar/coreutils/9.7/share/man/ (121 files)
-v(--verbose)
オプションを付けると省略されていたマニュアルファイルも表示されます。
timeoutコマンドを使ってみる
timeout
コマンドそのものを知らなかったので参考サイトに示した@ITのページを参考に実行に時間がかかり、時間切れになる可能性の大きいtraceroute
コマンドで、宛先をアルゼンチン国立図書館マリアーノ・モレーノにして使用してみました。以下に実行結果を示します。
$ timeout 10 traceroute www.bn.gov.ar
traceroute to www.bn.gov.ar (200.123.191.2), 64 hops max, 40 byte packets
1 aterm.me (192.168.10.1) 4.501 ms 3.541 ms 4.516 ms
2 ne-osa301.kddnet.ad.jp (113.157.227.251) 20.657 ms 20.382 ms 20.910 ms
3 27.86.45.17 (27.86.45.17) 20.828 ms 22.754 ms 23.661 ms
4 27.86.45.17 (27.86.45.17) 143.829 ms 143.885 ms
106.187.12.10 (106.187.12.10) 154.456 ms
5 106.187.12.26 (106.187.12.26) 133.834 ms 190.024 ms 142.488 ms
6 124.215.192.134 (124.215.192.134) 148.321 ms 141.933 ms
203.181.106.174 (203.181.106.174) 128.618 ms
7 124.215.192.134 (124.215.192.134) 133.040 ms 139.147 ms 208.827 ms
8 185.70.203.13 (185.70.203.13) 356.568 ms
185.70.203.89 (185.70.203.89) 268.450 ms
185.70.203.99 (185.70.203.99) 253.631 ms
9 185.70.203.13 (185.70.203.13) 286.003 ms 291.538 ms 288.200 ms