Linux tac command

Updated: 04/26/2017 by Computer Hope

About tac

Concatenate and print files in reverse.


tac (which is "cat" backwards) concatenates each FILE to standard output just like the cat command, but in reverse: line-by-line, printing the last line first. This is useful (for instance) for examining a chronological log file in which the last line of the file contains the most recent information.

If no FILE is specified, or if the FILE is specified as "-", tac reverses the contents of standard input.

tac syntax

tac [OPTION] ... [FILE] ...


-b, --before attach the line separator before each line of output instead of after.
-r, --regex interpret the line separator as a regular expression (useful with the -s option, see below).
-s, --seperator=STRING use STRING as the line separator instead of a newline.
--help display command help and exit.
--version output version information and exit.

tac examples

tac file1.txt

Prints the lines of file1.txt in reverse, from last line to first.

cat — Output the contents of a file.
tail — Print the last lines of a textfile.