← 返回命令列表

Linux command

tac 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Reverse lines

tac [file.txt]

Reverse lines

tac [file1.txt] [file2.txt]

Reverse with custom separator

tac -s "[separator]" [file.txt]

Reverse with regex separator

tac -r -s "[pattern]" [file.txt]

Reverse stdin

cat [file.txt] | tac

Reverse before separator

tac -b -s "[separator]" [file.txt]

说明

tac concatenates and prints files in reverse, line by line. The name is "cat" spelled backwards, reflecting its reversed functionality. By default, tac uses newline as the record separator, reversing line order. Custom separators can be specified, making it useful for reversing records in various file formats. The tool is handy for viewing log files (newest first), reversing sorted output, or processing data that needs to be in reverse order.

参数

-b, --before
Attach separator before instead of after record.
-r, --regex
Interpret separator as regular expression.
-s _string_, --separator= _string_
Use string as separator instead of newline.
--help
Display help information.
--version
Display version information.

FAQ

What is the tac command used for?

tac concatenates and prints files in reverse, line by line. The name is "cat" spelled backwards, reflecting its reversed functionality. By default, tac uses newline as the record separator, reversing line order. Custom separators can be specified, making it useful for reversing records in various file formats. The tool is handy for viewing log files (newest first), reversing sorted output, or processing data that needs to be in reverse order.

How do I run a basic tac example?

Run `tac [file.txt]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -b, --before do in tac?

Attach separator before instead of after record.