Reverse File Lines With tac
Output a file's lines in reverse order, the counterpart of cat.
Run tac file.txt to print the file from the last line to the first.
01Command
Command
$ tac file.txt02What 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
!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: tacEvidence: Documents tac, which concatenates and prints files in reverse line order.
- Debian package: coreutilsEvidence: Debian packages the GNU coreutils suite, which provides this command.
Last verified: 2026-09-20 · Category: Developer
06Related solutions
Update and upgrade packages on Debian/Ubuntu with apt
Refresh the package index from all configured repositories, then install newer versions of every upgradable package.
Search text recursively in a directory with grep
Find every occurrence of a pattern across all files in a tree, printed as file:line:number matches.
Extract a .tar.gz archive with tar
Unpack a gzipped tarball into the current directory while printing each file as it is extracted.