macOS 上大部分命令都为 BSD 提供的命令,部分与 GNU Linux 的命令有稍许不同。这在开发的时候经常给我们带来一些额外的麻烦,以下命令即可在 macOS 上替换/安装大部分 Linux 命令。

1
2
3
brew install autoconf bash binutils coreutils diffutils ed findutils flex gawk \
    gnu-indent gnu-sed gnu-tar gnu-which gpatch grep gzip less m4 make nano \
    screen watch wdiff wget util-linux

添加 PATH 环境变量:

1
echo "export PATH=\"/usr/local/opt/util-linux/bin:/usr/local/opt/util-linux/sbin:$PATH\"" >> ~/.zshrc

重载当前 zsh session:

1
source ~/.zshrc

大功告成🎉试试熟悉的命令吧~

1
$ namei /usr/local/bin/gtimeout

Reference

  1. Using GNU command line tools in macOS instead of FreeBSD tools
    https://gist.github.com/skyzyx/3438280b18e4f7c490db8a2a2ca0b9da
  2. namei command in MacOs
    https://stackoverflow.com/questions/28351828/namei-command-in-macos
  3. timeout command not available on mac os
    https://github.com/kubernetes-sigs/cluster-api-provider-gcp/issues/271

知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。