This page demistrates the syntax of the sort command and lists the most used options and how to use them.
Code |
Output |
*Note: These are the files that will be used in the examples below.
|
 |
-b option
Tells the command to ignore leading blanks.
|
 |
-d option
This option, also known as dictionary order, tells the command to only consider blanks and alpanumeric (alpha) characters.
|
 |
-f option
Tells the command to ignore the case of characters, thus it treats all characters as though they were uppercase characters.
|
 |
-g option
Also known as general numeric sort, this tells the command to compare characters according to numerical value.
|
 |
-i option
Tells the command to only consider printable characters, those found on the keyboard.
|
 |
-n option
This has the command sort based on the numerical value of the strings in the file, ASCII codes.
|
 |
-r option
This has the command reverse the result of the comparisons.
|
 |
-c option
This has the command check to see if the file is sorted, if the file is sorted then the command will not sort it.
|
 |
-m option
Has the command merge already sorted files, will not sort the files again.
|
 |
-s option
Also known as stable, this stops the command from running "last-resort comparison," this helps with efficiency.
|
 |
-u option
When used with the -c option the command checks for strict ordering, when used by itself will only output the first instance of a line that is identical to another line.
|
 |
-z option
Tells the command to end lines with zero bytes, not a new line character.
|
 |