52

I like to use tac to reverse the output of cat. However, it's not available in the Mavericks terminal. I tried to find it on MacPorts and again it's not available. Can anyone please show me how to get tac? It's very helpful for reading log files.

58

Yes:

  • Install Homebrew
  • brew install coreutils
  • ln -s /usr/local/bin/gtac /usr/local/bin/tac

or use MacPorts to install coreutils in a similar way.

  • I don't get how ln -s /usr/local/bin/gtac /usr/local/bin/tac made it work... Isn't that command only supposed to list some file memory blocks? – Timothy Swan Sep 27 '17 at 17:51
  • 1
    The symlink is just for convenience. Homebrew installs coreutil binaries in /usr/local/bin by prefixing their original name with a 'g'. ls becomes gls, head becomes ghead and so on. Consequently, tac is installed as gtac, and the symlink suggested in this answer is just to make tac available under that name. Omitting the symlink, you can still run the program as gtac. – grebneke Sep 27 '17 at 21:20
  • Oh. You're talking about ln -s not ls -s This makes more sense now. I must have entered it in correctly the first time. – Timothy Swan Sep 27 '17 at 21:29
59

On OS/X like on many systems (BSDs, Solaris, AIX, IRIX...), the functionality of GNU tac is available in tail with the -r option. So no need to install GNU tac:

tail -r the-file
  • 10
    So, alias tac='tail -r' will do the trick for OP! – mkc Feb 7 '14 at 17:18
  • 5
    Well, actually using a shell alias may fail because aliases don't transfer into shell scripts. Use a function like tac() { tail -r -- "$@"; } – kojiro Mar 1 '16 at 17:44
0

Install gnu coreutils already compiled with Rudix:

sudo rudix install coreutils

Or download and gui install Rudix coreutils

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.