Linux Terminal Command: tac
The tac command is an essential tool in File Manipulation & Viewing. In this tutorial, we will explore what tac does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The tac command is the reverse of cat. It reads files and prints their lines in reverse order (bottom line first, top line last).
Common Options & Syntax
tac [options] [arguments]
Here are the most common flags used with tac:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
tac logs.txt
What it does: Prints the lines of ’logs.txt’ in reverse order.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
tac system.log | grep -m 10 'ERROR'
What it does: Reads system logs starting from the bottom (newest logs) and pipes them to grep to find only the first 10 occurrences of ‘ERROR’.
⚙️ Warning & Common Pitfalls
[!WARNING] Because
tacmust parse lines from the bottom, it buffer-reads files and can be slow on extremely large archives.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out: