File Viewing & Editing

tac

Display file contents in reverse — last line first, first line last.

Synopsis

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

Examples

Print file lines in reverse order
tac file.txt
View last 20 log lines in reverse
tac access.log | head -20
Reverse blocks separated by ---
tac -s '---' data.txt

Common options

FlagDescription
-bAttach separator before instead of after
-rInterpret separator as a regex
-sUse specified string as separator

About tac

The `tac` command display file contents in reverse — last line first, first line last. Text viewing and editing commands are fundamental tools in any Linux user's toolkit.

Linux treats almost everything as a file, so the ability to quickly inspect, filter, transform, and edit file contents from the command line is critical. These commands are regularly combined with pipes and redirects to build powerful data-processing pipelines.

The command accepts 3 commonly used flags shown above, though the full set of options is available in the man page (`man tac`). The 3 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.

Related commands

More File Viewing & Editing Commands

Other commands in the File Viewing & Editing category

Related tools