Home·Terminal commands

tac

Text processing

Usage

tac [file]

Prints a file's lines from last to first; it is GNU coreutils, so macOS uses tail -r, and it is not rev, which reverses characters.

Common flags

FlagMeaning
-sUse another separator instead of the newline
-rRead the separator as a regular expression
-bPut the separator before each record rather than after

Examples

tac access.log | head

The newest lines first.

tail -r access.log

The macOS equivalent.

These were built to be piped together. Three joined commands are usually shorter than one that does everything.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does tac do?

Prints a file's lines from last to first; it is GNU coreutils, so macOS uses tail -r, and it is not rev, which reverses characters.

Q. How do I type it?

tac [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

3 are listed here; the full set is in man tac. This command sits under Text processing.

Related commands

man page: man tac