tac
file managementLinux/Unix
The tac command is one of the most frequently used commands in Linux/Unix-like operating systems. tac Concatenate and print files in reverse (opposite of cat)
Quick Reference
Command Name:
tac
Category:
file management
Platform:
Linux/Unix
Basic Usage:
tac [options] [arguments]
Common Use Cases
Syntax
tac [OPTION]... [FILE]...
Options
Option | Description |
---|---|
-b, --before |
Attach the separator before instead of after |
-r, --regex |
Interpret the separator as a regular expression |
-s, --separator=STRING |
Use STRING as the separator instead of newline |
--help |
Display help and exit |
--version |
Output version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the tac
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
Display file contents in reverse order (last line first)
tac file.txt
Display multiple files in reverse order
tac file1.txt file2.txt
Use standard input when no file is specified
echo -e "Line 1\nLine 2\nLine 3" | tac
Advanced Examples:
Reverse order of paragraphs (separated by blank lines)
tac -b -r -s '^$' document.txt
Use a custom separator instead of newline
tac -s ";" data.csv
Process a binary file (less common use case)
tac -b binary.dat