On this page
reference
1 min read
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.
| Option | Effect |
|---|---|
-s, --separator=STRING |
Use STRING as the separator between records, instead of a newline. |
-r, --regex |
Treat the separator as a regular expression rather than a literal string. |
-b, --before |
Expect 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
| Code | Meaning |
|---|---|
0 |
Every file was printed. |
1 |
A file could not be read, or the separator regular expression was invalid. |
See also
Peios Learn
Built with Trail