Text and processing

The sort command

Sorts the lines of a file or of the input. Alphabetical by default.

Syntax

sort [opciones] [archivo]Try it in the terminal →

Most useful options

-rReverse order
-nSorts numbers as numbers
-kSorts by a column
-uRemoves duplicates

Copy-ready examples

$ sort Documentos/tareas.txtAlphabetical order
$ printf '10\n2\n1\n' | sort -nNumeric order
$ printf 'b\na\nc\n' | sort -rReverse order

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • Without -n, 10 comes before 2 because it compares text.

Related commands

FAQ

How do I remove duplicates?

With sort -u, or piping to uniq if they are already grouped.

More Text and processing commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course