sort Command: Tutorial & Examples

Sort the lines of a file

The sort command is a Linux utility that is used to sort the lines of a text file or the output of a command. It is often used in combination with other commands to process and analyze data.

To use the sort command, you will need to specify the input file or the command whose output you want to sort. For example, to sort the contents of a file named input.txt, you might use the following command:

sort input.txt

This will read the contents of input.txt and sort the lines alphabetically. The sorted output will be displayed on the command line.

You can also use various options with the sort command to modify its behavior. For example, you can use the -r option to sort the lines in reverse order, or the -n option to sort the lines numerically.

The sort command is a useful tool for processing and analyzing data, and it is available on most Linux distributions. It can be used in combination with other commands, such as grep and awk, to extract and process specific information from a file or the output of a command.

Except where otherwise noted, content on this site is licensed under a CC BY-SA 4.0 license CC BY SA