tac
Print files in reverse line order
TLDR
Concatenate specific files in reversed order
Display stdin in reversed order
Use a specific separator
Use a specific regex as a separator
Use a separator before each file
SYNOPSIS
tac [OPTION]... [FILE]...
PARAMETERS
-b, --before
Append the separator to the beginning of the record that tac reads. By default, the separator is considered part of the *preceding* record.
-r, --regex
Interpret the separator string as a regular expression. This allows for more complex delimiter patterns.
-s, --separator=STRING
Use STRING as the record separator instead of the default newline character. Each instance of STRING defines the boundary between records.
--help
Display a help message and exit.
--version
Output version information and exit.
FILE
One or more input files to process. If no FILE is specified, or if FILE is a hyphen (-), tac reads from standard input.
DESCRIPTION
tac is the reverse counterpart of the cat command. While cat concatenates and prints files to standard output starting from the first line, tac concatenates and prints files from the last line, then the second-to-last, and so on, until the first line. This makes it particularly useful for examining log files where the most recent entries are typically appended at the end. By default, tac uses the newline character as its record separator, treating each line as a distinct record. However, it provides options to specify a different separator string and even interpret that separator as a regular expression, offering flexibility for various file formats. When no file is specified, or when a hyphen (-) is used as a filename, tac reads from standard input.
CAVEATS
When using custom separators, especially with the --before option, understanding how tac defines and includes the separator within a 'record' is crucial, as it can affect the output. Using regular expressions for separators (--regex) might incur a performance overhead for very large files compared to fixed string separators.
STANDARD INPUT/OUTPUT
If no input FILE is provided or if - is used as a filename, tac reads from standard input (e.g., from a pipe). The processed content is always written to standard output.
HISTORY
tac is a standard utility included in the GNU Core Utilities, making it widely available across most Unix-like operating systems. It was developed as a direct inverse to the ubiquitous cat command, addressing the common need to view files, particularly log files, in reverse chronological order. Its fundamental functionality has remained consistent since its inception.