Text and processing
The sort command
Sorts the lines of a file or of the input. Alphabetical by default.
Syntax
sort [opciones] [archivo]Most useful options
-rReverse order-nSorts numbers as numbers-kSorts by a column-uRemoves duplicatesCopy-ready examples
$ sort Documentos/tareas.txtAlphabetical order$ printf '10\n2\n1\n' | sort -nNumeric order$ printf 'b\na\nc\n' | sort -rReverse orderYou 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.
FAQ
How do I remove duplicates?
With sort -u, or piping to uniq if they are already grouped.
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