Topological Sort With tsort

Turn a list of dependency pairs into a valid execution order.

LinuxtextbuildcliLow risk
Run tsort deps.txt to print an order where each item comes after its prerequisites.

01Command

Command
$ tsort deps.txt

02What 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

RiskLow risk
RequirementsPreinstalled on Linux (GNU coreutils)
!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

Last verified: 2026-10-13 · Category: Developer

06Related solutions