Forrest logo
back to the tac tool

tac:tldr:22666

tac: Use a specific [r]egex as a [s]eparator.
$ tac -r -s ${separator} ${filename1 filename2 ---}
try on your machine

The tac command is a tool in Unix-like operating systems that's used to concatenate and display files in reverse order.

Here is a breakdown of the command:

  • tac: This is the main command that stands for "reverse cat" or "cat backward". It reads the input files line by line and writes them to the standard output in reverse order.

  • -r: This option is used to reverse the order of characters within each line. By default, tac reverses the order of entire lines, but with -r, it reverses only the characters within each line while maintaining the line order.

  • -s ${separator}: This option specifies a custom separator to be used when concatenating lines from multiple files. Instead of the default newline character, ${separator} is used as the separator between lines from different files.

  • ${filename1 filename2 ---}: These are the input files that you want to concatenate and display in reverse order. You can specify one or more filenames separated by spaces. The --- is used to indicate the end of the list of filenames.

So, the command tac -r -s ${separator} ${filename1 filename2 ---} will read the contents of the input files ${filename1 filename2 ---}, concatenate them, reverse their order line by line, and optionally reverse the characters within each line. The resulting reversed content will be displayed on the standard output.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the tac tool