Linux Command: tac
Concatenate and print files in reverse (last line first)
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.txtView recent log entries first
tac /var/log/syslog | head -20Reverse sort output
sort file.txt | tacPro 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 โ