tac Study Notes

tac is basically the reverse version of cat, but the key idea is not just reverse text, it reverses records (usually lines)

it prints a file from bottom to top instead of top to bottom

So if:

A
B
C

Then:

tac file.txt

Outputs:

C
B
A

What records means

A record is a chunk of text. By default, a record = a line (split by newline \n) So:

line1\nline2\nline3

becomes:

line3\nline2\nline1

Reverse multiple files

tac a.txt b.txt

each file is reversed separately, not merged then reversed


Read from stdin

tac

Type:

one
two
three

Output:

three
two
one