如何在 OS X 上获取 tac 命令?

pol*_*ise 68 osx cat

我喜欢用来tac反转cat. 但是,它在小牛队终端中不可用。我试图在 MacPorts 上找到它,但它又不可用。谁能告诉我如何获得tac?这对于阅读日志文件非常有帮助。

Sté*_*las 81

在 OS/X 上,就像在许多系统(BSD、Solaris、AIX、IRIX...)上一样,GNU 的功能 选项中tac可用。所以不需要安装 GNU :tail-rtac

tail -r the-file
Run Code Online (Sandbox Code Playgroud)

  • 所以,`alias tac='tail -r'` 将为 OP 提供帮助! (13认同)
  • [嗯,实际上](http://tirania.org/blog/archive/2011/Feb-17.html) 使用 shell 别名可能会失败,因为别名不会传输到 shell 脚本中。使用像 `tac() { tail -r -- "$@"; 这样的函数 }` (11认同)

gre*_*eke 72

是的:

  • 安装Homebrew
  • brew install coreutils
  • ln -s /usr/local/bin/gtac /usr/local/bin/tac 显然最新的 Homebrew 不需要,请参阅下面 Ran Ever-Hadani 的评论

或使用 MacPorts 以coreutils类似方式安装。

  • 除了 [grebneke](https://unix.stackexchange.com/users/32165/grebneke) 的回答:不再需要软链接。g 后缀现在仅在 osx 已有具有该名称的命令时才添加,因此 tac 安装为 tac,而不是 gtac。 (2认同)