TrumanWong

tac

Concatenate multiple files and print line-by-line reverse to standard output.

Summary

tac [OPTION]... [FILE]...

The main purpose

  • Display the file contents in reverse order by line. If there is no file or the file is -, read the standard input.
  • When processing multiple files, display each file in reverse order instead of connecting all files together and then displaying them in reverse.

Parameters

FILE (optional): The file to be processed, which can be one or more.

Options

Long options are equivalent to short options

-b, --before Concatenate delimiters before rather than after.
-r, --regex Treat delimiters as base regular expressions (BRE).
-s, --separator=STRING Use STRING as the separator instead of the default newline character.
--help Display help information and exit.
--version Display version information and exit.

return value

The return status is success unless illegal options or illegal parameters are given.

example

# Example selected from the official info document:
# Reverse a file character by character:
tac -r -s 'x\|[^x]' test.log

# About the -b option:
seq 1 3 |tac
# output
3
2
1
# Use the -b option:
seq 1 3 |tac -b
# Output, note that there is no newline character after 21:


3
twenty one
# The previous example is equivalent to converting '1\n2\n3\n' to '3\n2\n1\n'
# The previous example is equivalent to converting '1\n2\n3\n' to '\n\n3\n21'

Notice

  1. This command is a command in the GNU coreutils package. For related help information, please view man -s 1 tac or info coreutils 'tac invocation'.
  2. For details on basic regular expressions (BRE), see the REGULAR EXPRESSIONS section of man -s 1 grep.