The Linux Newbie Guide  ⇒    Fundamentals     Advanced     Supplement   Command Index   ENG⇒中
All rights reserved, please indicate the source when citing
  

sort - Sorting


The sort command is used to sort data in a text file, and it operates on a per-line basis. It can perform ascending or descending sorts on data in a text file, and it can also sort data based on specific fields.

The basic syntax of the sort command is as follows:

sort [OPTIONS] [FILE]

Some common options for the sort command include:

Example
$ echo -e '1 \n2\n5\n4\nAAA\n22\n11\n' <-Output as follows
1
2
5
4
AAA
22
11
$ echo -e '1 \n2\n5\n4\nAAA\n22\n11\n' | sort <-Sorting the previous output using 'sort'
11
2
22
3
5
AAA

For more sort options and additional examples and explanations, please refer to the provided link.