tac command

The tac command is much like its brother, the cat command. It also concatenates and prints a file to the screen. However, the tac command does this in reverse. This can be especially useful if you are looking for information that should be at the end of a long log file. For instance, if you needed to pull information on an email that was sent today and the log file rotates monthly, it would be more efficient to use the tac command as opposed to the cat command. The information will be printed to the screen in reverse order, starting at the last line.

Command: tac
Synopsis: tac [OPTION]… [FILE]…

Below are the different options that are available to customize the cat command.

OptionLong NameDescription
-b–beforeAttach the separator before instead of after.
-r–regexInterpret the separator as a regular expression.
-s–separator=STRINGUse STRING parameter as the separator instead of newline.


Base command This example uses the base tac command on a file named test.txt. This is the same file used in the cat article, so you can see that it is printed to the screen in reverse.

$# tac test.txt adipiscing sapien. Cras vel aliquet massa. Mauris quis auctor eros. Ut gravida tellus at nisi facilisis, adipiscing cursus nisi luctus. Morbi eu dictum felis. Morbi vel ipsum nunc. Nunc ac sapien viverra, dignissim arcu vitae, gravida magna. Phasellus a  imperdiet egestas sit amet eget ante. Nulla at fermentum turpis. In convallis leo nec lectus accumsan, id vehicula dui tincidunt. Proin eget pellentesque lectus. Duis id mauris vel massa   Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Was this article helpful? Let us know!