12. sort

The sort command is useful for sorting lines.

file1.txt
dog
cow
cat
elephant
bird

$ sort file1.txt
bird
cat
cow
dog
elephant

You can also do a reverse sort:

$ sort -r file1.txt
elephant
dog
cow
cat
bird

And also sort by numerical value:

$ sort -n file1.txt
bird
cat
cow
elephant
dog

Sign in to save your learning progress

Sign in

Exercises

Practice makes perfect! Here are some hands-on labs to reinforce your understanding of the sort command and text processing:

  1. Linux sort Command: Text Sorting - This lab provides a direct introduction to the sort command, allowing you to practice sorting lines of text files in various ways, including ascending and descending order.
  2. Word Count and Sorting - In this challenge, you'll apply your knowledge of sorting along with word counting to analyze text data, helping you find frequent patterns and sort data efficiently.

These labs will help you apply the concepts in real scenarios and build confidence with text manipulation and sorting in Linux.

Quiz

What flag do you use to perform a reverse sort?