tac

tac prints a file with its lines in reverse — the last line first, the first line last. The name is cat spelled backwards, which is exactly what it does.

tac [options] [file...]
$ tac events.log

Reversing a log file so the newest entries come first is the everyday use. With no file, tac reads standard input.

Reversing on something other than lines #

tac does not have to split on newlines. You can tell it to treat some other string as the separator, and it will reverse the order of the pieces between those separators.

OptionEffect
-s, --separator=STRINGUse STRING as the separator between records, instead of a newline.
-r, --regexTreat the separator as a regular expression rather than a literal string.
-b, --beforeExpect the separator before each record rather than after it. This matters for how the separator is reattached when the records are reordered.
$ tac -s ', ' -r names.csv

Exit status #

CodeMeaning
0Every file was printed.
1A file could not be read, or the separator regular expression was invalid.

Edit this page