LoginSignup
9
5

More than 3 years have passed since last update.

macでGNUコマンドを使う

Last updated at Posted at 2020-12-15

背景

Unixコマンドを書籍やブログ通りに実行しても同じ結果にならない。。。ので調べていると、UnixコマンドはBSD系のOS(macOSやFreeBSD)とLinux系のOS(GNU)で異なる実装がされているのですね。
自分の環境(macOS)でもGNUコマンドが使用できるようにします。

参考:Homebrew で macOS に GNU コマンドをインストールする

環境

PC: MacBook Pro 2020
OS: macOS Catalina (10.15.5)
shell: zsh (5.7.1)

方法

Homebrewでインストールします。

brew install coreutils
brew install grep

coreutilsではcutやsortなど複数のコマンドがインストールされます。
root_cb6ba2bbd7c6___Users_tt.png
既存のコマンドと区別するためGNUコマンドはgを先頭につけるようにとあります。すなわちGNUのcutやsortを使う場合はgcutやgsortと入力します。
coreutilsでインストールされたコマンドは「/usr/local/Cellar/coreutils/8.32/bin」にあります。
root_cb6ba2bbd7c6___Users_tt.png
個人的に使いたかったgrepはcoreutilsには含まれていないので別途インストールしています。

結果

grep(BSD grep)とggrep(GNU grep)のバージョン情報を表示させてみます。問題なくインストールできているようです。

grep --version; ggrep --version

root_cb6ba2bbd7c6___Users_tt.png

9
5
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
9
5