Easy Tutorial
❮ Linux Comm Mtools Linux Comm Setconsole ❯

Linux sort Command

Linux Command Manual

The Linux sort command is used to sort the contents of a text file.

sort can sort the contents of a text file line by line.

Syntax

sort [-bcdfimMnr][-o&lt;output file>][-t<delimiter>][+&lt;start field>-&lt;end field>][--help][--version][file][-k field1[,field2]]

Parameter Description:

Example

To sort the lines of a file using the default method with the sort command, use the following command:

sort testfile

The sort command will sort the first column of the text file in ASCII order by default and output the result to the standard output.

Using the cat command to display the testfile file shows the original order as follows:

$ cat testfile      # Original order of testfile  
test 30  
Hello 95  
Linux 85

The result after using the sort command is as follows:

$ sort testfile # Rearranged result  
Hello 95  
Linux 85  
test 30

Using the -k parameter to sort by the second column, the result is as follows:

$ sort testfile -k 2
test 30  
Linux 85 
Hello 95

Linux Command Manual

❮ Linux Comm Mtools Linux Comm Setconsole ❯