Linux tac Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux tac Guide
Complete beginner-friendly guide to tac on Linux, covering Arch Linux, CachyOS, and other distributions including reversing file output, line reversal, and reverse file display.
Table of Contents
tac Basics
Reverse File
Basic usage:
# Reverse file
tac file.txt
# Displays file in reverse order
From Input
Pipe input:
# Reverse from input
cat file.txt | tac
# Reverses piped input
Reversing Files
Line Reversal
Reverse lines:
# Reverse lines
tac file.txt
# Last line first, first line last
Multiple Files
Reverse multiple:
# Multiple files
tac file1.txt file2.txt
# Reverses each file
Separator Control
Custom Separator
Set separator:
# Custom separator
tac -s "---" file.txt
# -s = separator (splits on "---")
Regex Separator
Regex pattern:
# Regex separator
tac -r -s "^Chapter" file.txt
# -r = regex (treats separator as regex)
Multiple Files
Concatenate Reversed
Multiple files:
# Multiple files
tac file1.txt file2.txt
# Reverses each file separately
Combined Output
All together:
# Combined
tac file1.txt file2.txt > output.txt
# Reverses and combines
Troubleshooting
tac Not Found
Check installation:
# tac is part of coreutils
# Usually pre-installed
# Check tac
which tac
Summary
This guide covered tac usage, file reversal, and reverse file display for Arch Linux, CachyOS, and other distributions.
Next Steps
- cat Guide - Display files
- head Guide - View file beginnings
- tail Guide - View file endings
- tac Documentation:
man tac
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.