Created
May 25, 2026 20:44
-
-
Save copyleftdev/45849486344a668ba73a3e9847b97f92 to your computer and use it in GitHub Desktop.
tac — reverse line order of any file or stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # tac — cat backwards: last line first | |
| # (tac is cat spelled backwards) | |
| tac logfile.log # reverse entire file | |
| tac logfile.log | head -20 # last 20 lines, newest-first | |
| tac logfile.log | grep -m1 'ERROR' # last occurrence of ERROR | |
| # Process a JSONL file newest-first: | |
| tac data.jsonl | head -5 | python3 -c " | |
| import sys, json | |
| for line in sys.stdin: | |
| print(json.loads(line)['id']) | |
| " | |
| # vs tail -f: use tac for complete reversed files, | |
| # use tail -f for live-streaming a growing file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment