sort is a standard command line program that prints the lines of its input or concatenation of all files listed in its argument list in sorted order.

# To sort a file in ascending order:
sort <filename>

# To sort a file in descending order:
sort -r <filename>

# To sort a file using numeric rather than alphabetic order:
sort -n <filename>

# To sort the passwd file by the 3rd field, numerically:
sort -t: -k 3n /etc/passwd

# To sort a file preserving only unique lines:
sort -u <filename>

# To sort a file randomly:
sort -R <filename>