Reverse File Lines With tac

Output a file's lines in reverse order, the counterpart of cat.

LinuxTerminalscriptingLow risk
Run tac file.txt to print the file from the last line to the first.

01Command

Command
$ tac file.txt

02What it does

tac is cat backwards: it outputs the last line first. It is useful for reading append-only logs newest-first, or for reversing generated lists. A separator other than newline can be set with -s, and -b moves the separator to the front.

03Risk

RiskLow risk
RequirementsGNU coreutils (preinstalled on Linux)
!Warning: tac buffers by separator and loads data into memory; extremely large files without newlines can consume a lot of RAM.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • GNU coreutils: tac
    GNU · vendor-doc · 2026-09-20
    Evidence: Documents tac, which concatenates and prints files in reverse line order.
  • Debian package: coreutils
    Debian · vendor-doc · 2026-09-20
    Evidence: Debian packages the GNU coreutils suite, which provides this command.

Last verified: 2026-09-20 · Category: Developer

06Related solutions