2748

14 分钟

#Bash 的 tac 命令

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

功能

将文件的内容顺序逆转,拼接多个文件并打印到标准输出。

文件内顺序逆转,文件之间顺序不变。

类型

可执行文件(/usr/bin/tac),属于 coreutils

参数

  • OPTION 选项:
    • -b, --before - 将分隔符放在前面而不是后面
    • -r, --regex - 将分隔符当作正则表达式解析
    • -s, --separator=STRING - 使用 STRING 作为分隔符;默认为换行符(\n
    • --help - 显示帮助
    • --version - 显示版本
  • FILE - 文件列表;如果没有这个参数或指定为 -,则读取标准输入

#示例

$ cat 1.txt 2.txt # 正序查看文件内容 1 2 3 A B C $ tac 1.txt 2.txt # 逆序查看文件内容 3 2 1 C B A

#相关命令

命令说明
cat正序拼接文件内容并打印到标准输出

#推荐阅读

#手册

TAC(1) User Commands TAC(1) NAME tac - concatenate and print files in reverse SYNOPSIS tac [OPTION]... [FILE]... DESCRIPTION Write each FILE to standard output, last line first. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too. -b, --before attach the separator before instead of after -r, --regex interpret the separator as a regular expression -s, --separator=STRING use STRING as the separator instead of newline --help display this help and exit --version output version information and exit AUTHOR Written by Jay Lepreau and David MacKenzie. REPORTING BUGS GNU coreutils online help: <https://www.gnu.org/software/coreutils/> Report any translation bugs to <https://translationproject.org/team/> COPYRIGHT Copyright © 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO cat(1), rev(1) Full documentation <https://www.gnu.org/software/coreutils/tac> or available locally via: info '(coreutils) tac invocation' GNU coreutils 9.4 April 2024 TAC(1)

创建于 2025/12/5

更新于 2025/12/5