Can you use the tac command in Terminal?

我是研究僧i 提交于 2019-12-08 03:18:32

问题


I'm trying to search a large file in reverse order from the command line (using terminal). I found the tac command: http://clifgriffin.com/2008/11/25/tac-and-reverse-grep/

tac is the inverse of cat. However, when I try to use the tac command in terminal, it says that command doesn't exist. Is there a way I'd be able to use tac in terminal? What are some other fast ways to search a file from the end via the command line?


回答1:


The MacOs version of tail support the -r ("reverse") option, and defaults to displaying the entire file from the end. So tail -r filename should be exactly equivalent to tac filename.

Or, you could try building tac yourself from the source code. It's part of the GNU coreutils package.




回答2:


It's easy using OSX Homebrew:

brew install coreutils

Then it's available as gtac (as in GNU tac), for example:

# Find and parallel copy all files in reverse order
find . -print | gtac | parallel copy "{}" destination/


来源:https://stackoverflow.com/questions/7533462/can-you-use-the-tac-command-in-terminal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!