sort (sort lines of text files)

This command is useful for bringing alphabetical or numerical order to data. Consider the following example:

sort /etc/group

This will output the lines of the file /etc/group in alphabetical order. You'll get a neatly sorted list of groups present on your system. Compare this with the unsorted output of cat /etc/group. To sort input lines in numerical order, use sort with the -n option. For example:

cut -d : -f 3 /etc/group | sort -n

The →cut command will extract the third column from the file /etc/group. This column contains groups' ID numbers. The sort -n command will output these IDs in ascending order. Use sort's -r option to sort lines in reverse order.