Sort Command
Part of the Fundamentals section of Coddy's Terminal journey — lesson 32 of 82.
The
Simply type
The output will be:
Useful flags:
Without
Nota:
sort command arranges the lines of a file in alphabetical or numerical order.We have fruits.txt:banana
apple
cherry
mango
sort followed by the filename:sort fruits.txtapple
banana
cherry
mango-r — sort in reverse (descending) order:sort -r fruits.txt-n — sort numerically instead of alphabetically:sort -n numbers.txt-n, numbers are sorted as text, so 10 would come before 2. With -n, they sort correctly by value.-u — sort and remove duplicate lines at the same time:sort -u fruits.txt-k — sort by a specific column (useful for files with multiple columns):sort -k2 data.txt # sort by the second columnsort no modifica el archivo original — solo imprime el resultado ordenado en la pantalla.Challenge
BeginnerUse the sort command on fruits.txt:
- Sort the file in alphabetical order using
sort - Sort the file in reverse alphabetical order using
sort -r
Hint: Run both commands one after the other. The original file is not changed —
sortonly prints the result.
Try it yourself
Terminal
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline