14 Useful Examples of Linux ‘sort’ Command – Part 1

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

7 Responses

  1. Aditya Garg says:

    1. A key specification like -k2 means to take all the fields from 2 to the end of the line into account. To sort by a single column, use -k2,2 as the key specification. This means to use the fields from #2 to #2, i.e. only the second field.

    2. While doing something like “sort -nk5,5 table.txt“, why does the sort command remove entries with 0? (have files with size 0-should get sorted not removed)

  2. dragonmouth says:

    The link to 7 Interesting Sort Commands does not work properly. It loads this article

    There are only 10 ‘sort’ command examples. The other four entries just create files to be input to the ‘sort’ command examples.

  3. Johnny Rosenberg says:

    Hi!
    Just wondering why you type ”/home/$USER/” instead of just ”$HOME/”. Unnecessary typing. Just saying. :) Or am I missing something?

  4. sealinger says:

    In the last command:

    $ ls -l /home/$USER | sort -t "," -nk2,5 -k9

    Why you put a parameter -t ? I don’t understand…

  5. OKCarl says:

    I have a copy of a 4.09 GB wordlist / dictionary, crackstation.txt. Just now the words and numbers are arranged in the usual order: 0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStT uUvVwWxXyYzZ

    How do I rearrange the order to something like:

    tTaAsShHwWiIoObBmMfFcCdDpPnNeEgGrRyYuUvVjJkKqQzZxX 1023985467

    (This sequence gives the first letters of English words in order of popularity, from most popular (left) to least popular (right))

  6. Anonymous says:

    “14 Useful Examples…”

    No, it’s 14 numbered entries, but several are just duplicate functions of sort using files vs using standard input.

  7. Meme says:

    Hello, what program are you use to create gif such as above?

Leave a Reply to Aditya Garg Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.