sort

Linux · Text · available in the simulator

What it does

Sorts lines of text files.

Syntax

sort [opciones] [archivo...]

Options and parameters

  • -r

    Reverses the result of comparisons.

  • -n

    Compares according to string numerical value instead of alphabetically.

    sort -n numeros.txt
  • -u

    Outputs only the first of an equal run; removes duplicates.

  • -k N

    sorts by column N

  • -k

    Sorts via a key; sorts by the specified field.

    sort -k2 datos.txt
  • -t

    Uses the specified character as the field separator.

    sort -t: -k3 -n /etc/passwd
  • -h

    Compares human-readable numbers like 2K or 1G.

  • -f

    Folds lower case to upper case characters (ignores case).

  • -o

    Writes result to the specified file instead of standard output.

Usage examples

  • sort archivo.txt
  • sort -r archivo.txt
  • sort -n numeros.txt
  • sort -u archivo.txt
  • sort nombres.txt
  • sort -nr notas.txt
  • sort -k2 datos.txt
  • sort -t: -k3 -n /etc/passwd
Practise sort

Related commands