๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

๐Ÿ’ก Text Processing August 20, 2026 6

Linux Command: tac

Concatenate and print files in reverse (last line first)

Terminal โ€” Text Processing
Command
$ tac file.txt

tac (cat reversed) displays files with lines in reverse order โ€” the last line becomes the first and the first becomes the last. It is the line-level complement to rev (which reverses characters within a line). tac is useful for viewing log files (most recent entries first), reversing sorted output, processing files from bottom to top, and building reverse chronological views. tac reads the entire file into memory, so it may not be suitable for very large files. For large log files, consider tail for viewing recent entries.

Syntax

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

Key Options

  • -b โ€” Attach separator before instead of after
  • -r โ€” Use regex as separator
  • -s โ€” Use STRING as separator instead of newline

Examples

Reverse file lines

tac file.txt

View recent log entries first

tac /var/log/syslog | head -20

Reverse sort output

sort file.txt | tac

Pro Tips

  • tail -n 20 shows last 20 lines in order. tac file | head -20 shows last 20 lines in reverse. Use tac for reverse chronological views.
  • tac reverses line ORDER (last line first). rev reverses characters WITHIN each line. They are different operations.
  • tac reads the entire file into memory. For very large files (multi-GB), use tail or sed for viewing the end.

Learn more: Full tac reference โ†’

Share this tip