Technology and General Blog

The form command obtainable in Linux allows users to carry out sorting operations on a file or an input. The type command is useful when we want to get an purchased output of a file ascending, descending, or personalized-defined sort purchase.  By default, the form command does not change the unique file unless the output is redirected back again to the file.

This report covers how to use the type command to conduct sorting operations on unique columns in a file.

Basic Use

The type command is simple to use and quite useful in every day Linux functions. The general syntax of the command is as:

The solutions you go to the command modifies how the file is sorted and the precise problems to sort the target file. You can omit the selections to use the default sorting parameters.

By default, the sort command:

  • Kinds the alphabets in ascending purchase.
  • Letters arrive immediately after numerical values
  • Assigns better priority to lowercase letters than to uppercase letters.

For example, to sort a file without solutions:

The moment we operate the sort command against the file, we get the info sorted in alphabetical order (ascending).

Notice: Numerical values choose priority as from the instance earlier mentioned.

Type Command Solutions

You can use the adhering to choices in conjunction with the uncooked command to modify how the values are sorted.

  • -n – sorts in numerical values.
  • -h – compares human-readable quantities this sort of as 1k, 1G
  • -R – type in random order but team the similar keys.
  • -r – form the values in reverse (descending order).
  • -o – save ouput to a file
  • -c – look at if the enter file is sorted do not sort if true.
  • -u – show exclusive values only.
  • -k – sort the knowledge by using a certain important (handy when sorting columnar information).

Those are some well known selections you can tweak to get the most effective-sorted outcome. For much more selections, check out the guide.

How to Sort In Linux Bash By Numerical Values

How to Kind In Linux Bash By Reverse Order

To kind enter in reverse purchase, we use the -r flag. For example:

The command earlier mentioned will sort in ascending alphabetical purchase (numerical values 1st) and reverse buy.

How to Kind In Linux Bash by Column

Kind lets us to form a file by columns by applying the -k selection. Let us get started by building a file with far more than a single column. In sort, we different a column by a single area.

In the example file underneath, we have 6 columns.

To form the captains’ file previously mentioned by their century, we can specify the -k followed by the column variety as:

After we specify the column to sort the data, the sort command will attempt to type the values in ascending order. In the case in point higher than, the command sorts the values from the earliest century to the most current.

To kind by the first name, set the kind column as 1:

How to Help you save Kind Output to a File

To help you save the sorted output to a file, we can use the -o choice as:

$ kind -k 5 -o captains_century captains.txt

The command earlier mentioned will kind the captains.txt file by the 5th column and preserve the final result to the captains_century.txt file.


That is the conclusion of this tutorial on the sort command in Linux. We coated the fundamental principles of working with the type command to get the most out of your sorted facts. Really feel free of charge to take a look at how you can use the kind command.

Leave a Reply

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