Linux sort command: Sort the data in a file
Linux sort command Function Description
Use the sort command to sort the data in a file and display the results on the standard output.
Linux sort command Syntax
sort [Option] [File]
The meaning of each option in the command is shown in the table:
Option | Description |
---|---|
-m | If the given files are already in order, then merge the files |
-u | Keep only one of the rows that are considered the same after sorting |
-d | Sort by dictionary order, only letters, numbers, spaces and tabs have meaning when comparing |
-f | Treat lowercase letters the same as uppercase letters |
-I | Ignore non-printing characters |
-M | As a month comparison, such as JAN<FEB |
-r | Output sorted results in reverse order |
-c | Check if the given files are in order, if they are not in order, print an error message and exit with a status of 1 |
Linux sort command Demo
Sort the file textfile1 data and display it on the screen
[root@rhel ~]# cat textfile1
a
b
c
// View the file contents of file textfile1
[root@rhel ~]# sort textfile1
a
b
c
Read the contents of file /root/apidemos.com.sort.txt, sort the file in reverse order and display it on the screen
sort -r /root/apidemos.com.sort.txt
Output: