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.

Output

-b option

         Tells the command to ignore leading blanks.

Output

-d option

         This option, also known as dictionary order, tells the command to only consider blanks and alpanumeric (alpha) characters.

Output

-f option

         Tells the command to ignore the case of characters, thus it treats all characters as though they were uppercase characters.

Output

-g option

         Also known as general numeric sort, this tells the command to compare characters according to numerical value.

Output

-i option

         Tells the command to only consider printable characters, those found on the keyboard.

Output

-n option

         This has the command sort based on the numerical value of the strings in the file, ASCII codes.

Output

-r option

         This has the command reverse the result of the comparisons.

Output

-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.

Output

-m option

         Has the command merge already sorted files, will not sort the files again.

Output

-s option

         Also known as stable, this stops the command from running "last-resort comparison," this helps with efficiency.

Output

-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.

Output

-z option

         Tells the command to end lines with zero bytes, not a new line character.

Output