How to do it...

  1. We can sort a set of files (for example, file1.txt and file2.txt), like this:
        $ sort file1.txt file2.txt > sorted.txt

 Alternatively, use this:

        $ sort file1.txt file2.txt -o sorted.txt
  1. For a numerical sort, we use this:
        $ sort -n file.txt
  1. To sort in the reverse order, we use the following command:
        $ sort -r file.txt
  1. To sort by months (in the order Jan, Feb, March,...), use this:
        $ sort -M months.txt
  1. To merge two already sorted files, use this command:
        $ sort -m sorted1 sorted2
  1. To find the unique lines from a sorted file, use this:
        $ sort file1.txt file2.txt | uniq
  1. To check whether a file has already been sorted, use the following code:
        #!/bin/bash 
        #Desc: Sort 
        sort -C filename ; 
        if [ $? -eq 0 ]; then 
           echo Sorted; 
        else 
           echo Unsorted; 
        fi 

Replace filename with the file you want to check and run the script.