Topological Sort With tsort
Turn a list of dependency pairs into a valid execution order.
Run tsort deps.txt to print an order where each item comes after its prerequisites.
01Command
Command
$ tsort deps.txt02What it does
tsort performs the same topological sort that build systems use, reading pairs like 'a b' meaning a before b. It is handy for ordering migration scripts, service starts or generated tasks from a dependency description without writing a graph algorithm.
03Risk
!Warning: If the input contains a cycle, tsort reports it and may omit some items; verify the dependency list.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- tsort.1.en.html manual page (Debian bookworm)Evidence: Documents tsort, which performs a topological sort of paired items.
Last verified: 2026-10-13 · Category: Developer