sort

Order lines alphabetically, numerically, or by a key

About

Rearranges input lines according to the comparison you choose. It can also remove duplicates or merge already-ordered streams. Key selection orders by a particular column while whole lines stay intact.

Install it

Included with Termux

Run this inside Termux. If the package is already present, pkg will say so and do nothing.

Commands worth knowing

6 of the invocations you will actually reach for. Tap the copy button to put one on your clipboard.

sort names.txt Arrange lines in ascending alphabetical order.
sort -n scores.txt Compare as numbers, so 10 comes after 9 and not after 1.
sort -r scores.txt Reverse the order, largest values first.
sort -k2 -n data.txt Order rows by the second column, treated as a number.
sort -u emails.txt Collapse duplicate adjacent lines, so each value appears once.
sort -h sizes.txt Compare human-readable sizes such as 4K and 2M by real magnitude.

Worked example

Run sort -n scores.txt and this is what you should see.

termux
$ sort -n scores.txt
9 alice
17 bob
42 carol
88 dave

Developed by

GNU Project .