国际访客建议访问 Primers 编程伙伴 国际版站点 > Bash 教程 > tsort 以获得更好的体验。

# Bash 的 tsort 命令

tsort [OPTION] [FILE]

!subtitle:功能

对文件内容进行拓扑排序。

!subtitle:类型

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

!subtitle:参数

  • OPTION 选项:

    • --help - 显示帮助

    • --version - 显示版本

  • FILE - 如果没有这个参数或指定为 -,则读取标准输入

# 示例

$ cat 1.txt         # 查看文件
F G
D E
A B
E F
C D
D E
$ tsort 1.txt       # 拓扑排序
A
C
B
D
E
F
G

源文件表示 F -> G, D -> E, A -> B, E -> F, C -> D, D -> E,拓扑排序后得到 A -> B -> C -> D -> E -> F -> G

# 推荐阅读

# 手册

TSORT(1)                         User Commands                        TSORT(1)

NAME
       tsort - perform topological sort

SYNOPSIS
       tsort [OPTION] [FILE]

DESCRIPTION
       Write  totally  ordered  list  consistent  with the partial ordering in
       FILE.

       With no FILE, or when FILE is -, read standard input.

       --help display this help and exit

       --version
              output version information and exit

AUTHOR
       Written by Mark Kettenis.

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
       Full documentation <https://www.gnu.org/software/coreutils/tsort>
       or available locally via: info '(coreutils) tsort invocation'

GNU coreutils 9.4                 April 2024                          TSORT(1)
本文 更新于: 2026-03-06 09:52:35 创建于: 2026-03-06 09:52:35