The sort command will sort the contents of a file (or redirected output from another command) using the entire line as the sort key.
head americanpie.txt | sort
Addition of the –r flag will reverse the sort order:
head americanpie.txt | sort –r
By default a the sort is done character by character along the line, which doesn’t always make the most sense when sorting numbers:
The addition of the –n flag makes the program sort in numerical order:
sort –n numbers.txt