tsort [file]
tsort reads input from files (or from the standard input if you do not specify a file) and produces an ordered list of items consistent with a partial ordering of items provided by the input.
Input to tsort takes the form of pairs of items (nonempty strings) separated by blanks. A pair of two different items indicates ordering. A pair of identical items indicates presence, but not ordering.
tsort <<EOF
a b c c d e
g g
f g e f
h h
EOF
produces the output:
a
b
c
d
e
f
g
h
See Localization for more information.
POSIX.2, X/Open Portability GuideX/Open Portability Guide.