Skip to content

Instantly share code, notes, and snippets.

@copyleftdev
Created May 25, 2026 20:44
Show Gist options
  • Select an option

  • Save copyleftdev/45849486344a668ba73a3e9847b97f92 to your computer and use it in GitHub Desktop.

Select an option

Save copyleftdev/45849486344a668ba73a3e9847b97f92 to your computer and use it in GitHub Desktop.
tac — reverse line order of any file or stream
# 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