Bash Using sort Numeric sort

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Suppose we have this file:

test>>cat file
10.Gryffindor
4.Hogwarts
2.Harry
3.Dumbledore
1.The sorting hat

To sort this file numerically, use sort with -n option:

test>>sort -n file  

This should sort the file as below:

1.The sorting hat  
2.Harry  
3.Dumbledore  
4.Hogwarts  
10.Gryffindor

Reversing sort order: To reverse the order of the sort use the -r option

To reverse the sort order of the above file use:

sort -rn file

This should sort the file as below:

10.Gryffindor
4.Hogwarts
3.Dumbledore
2.Harry
1.The sorting hat


Got any Bash Question?