Linux commands: sort

Quick startsortCommand to sort records/text lines

Suppose you have a text file containing dog names:

The list is unordered.

ThissortCommands help us sort them by name:

userOptions for reversing orders:

By default, the sorting is case-sensitive and sorted alphabetically. use--ignore-caseChoose a case-insensitive option, and-nOption to sort in numerical order.

If the file contains duplicate lines:

you can use it-uChoose to delete them:

sortNot only for files, because many UNIX commands also work for pipes, so you can use on the output of another command, for example, you can sort the files returned by the following commandlswith:

ls | sort

sortThe function is very powerful, there are more options, you can explore the callman sort.

ThissortThis command can be used in Linux, macOS, WSL and wherever you have a UNIX environment

Download mine for freeLinux Command Manual

More cli tutorials: