SORT command is used to sort a file, arranging the records in a particular order. By default, the sort command sorts file assuming the contents are ASCII. Using options in sort command, it can also be used to sort numerically. SORT command sorts the contents of a text file, line by line. sort is a standard command line program that prints the lines of its input or concatenation of all files listed in its argument list in sorted order. The sort command is a command line utility for sorting lines of text files. It supports sorting alphabetically, in reverse order, by number, by month and can also remove duplicates.
The sort command can also sort by items not at the beginning of the line, ignore case sensitivity and return whether a file is sorted or not. Sorting is done based on one or more sort keys extracted from each line of input. By default, the entire input is taken as sort key.
A couple of days ago I was asked how to sort the output from the Unix and Linux ls command. Off the top of my head I knew how to sort the ls output by file modification time, and also knew how to sort ls with the Linux sort command, but I didn't realize there were other cool file sorting options available until I looked them up.In this short tutorial I'll demonstrate the Unix/Linux ls command file sorting options I just learned.
Unix ls command - sort by filename extensionAnother cool thing I didn't know is that you can also sort ls command output by filename extension. All you have to do is use the '-X' argument, as shown in this example:ls -1X(The arguments there are the number one (1) and the capital letter 'X'.