Linux and Unix tac command

Quick links

About tac
Syntax
Examples
Related commands
Linux and Unix main page

About tac

Concatenate and print files in reverse.

Description

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.

Syntax

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

Options

-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.

Examples

tac file1.txt

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

Related commands

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