On Unix-like operating systems, the tac command catenates and prints the contents of files, in reverse, line by line.

This page covers the GNU/Linux version of tac.

Description

tac (which is “cat” backwards) concatenates each FILE to standard output 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 where the last line of the file contains the most recent information.

  • Description
  • Syntax
  • Examples
  • Related commands
  • Linux commands help

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

Syntax

tac [OPTION] … [FILE] …

Options

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