• Main Menu
  • How to Use the Unix Sort Command


    The Unix sort command is a command for the Unix family of operating systems. It is designed to sort whatever information you give it. The command can be used for a variety of purposes, but it is most frequently employed when there are a number of different files which need to be ordered in some particular way. When the command is executed, the files which were sorted will be printed to the screen in an easy to view box with the files sorted per your instructions.

    Using the Unix sort command is very easy and only requires the most basic of command line knowledge. While there are a few parameters that can be passed to the sort command and a few flags that may be of use to you for more complex sorting, the basic function is very easy to use. For a pipeline sort, the command “ps -ef | sort” is used; and for a numeric sort, the command “ls -al | sort” is used.

    Some of the various flags that can be used for the sort command include: -r if you wish to sort your data in the reverse order, -f if you wish to ignore the specific case of a letter, -n if you want to do a numeric sort, -b if you wish to ignore any leading blank spaces, and -M if you wish to sort by month.

    Below is an example of a numeric sort:

    ls -al | sort +4n | more

    This Unix sort command will sort the data in ascending, or smallest to largest, numeric order. The more command is used in case the data may be too much to fit on one screen. This same function, in the reverse order, can be written as so:

    ls -al | sort +4nr | more

    This Unix sort command will perform the same sort over the same data as the previous sort function, but it will list the data in descending order, or largest to smallest.

    Got Something To Say:

    Your email address will not be published. Required fields are marked *

    Unix
    171 queries in 0.530 seconds.