Linux sort Command: Sorting Files, Numbers, and Columns
HardReset.InfoDecember 16, 20256 min15 views
10 connectionsΒ·15 entities in this videoβSorting Text Files Alphabetically
- π‘ The
sortcommand in Linux can easily sort text files alphabetically. - π To sort a file named
letters.txt, use the commandsort letters.txt.
Reversing Sort Order
- π To sort in reverse alphabetical order, add the
-roption:sort -r letters.txt. - π― This changes the order from A-Z to Z-A.
Sorting Numbers Numerically
- π’ For numerical sorting, use the
-noption:sort -n numbers.txt. - π This sorts numbers from smallest to largest.
- π Combine
-nand-r(sort -n -r numbers.txt) to sort numbers from largest to smallest.
Removing Duplicate Lines
- ποΈ Use the
-uoption to remove duplicate lines:sort -u letters.txt. - π― For numbers, combine
-nand-u:sort -n -u numbers.txt. - ποΈ You can also combine
-n,-u, and-rfor reverse numerical unique sorting.
Sorting by Specific Columns
- ποΈ The
-koption allows sorting by a specific column. - π» To sort
psoutput by the first column (username), useps aux | sort -k 1. - π You can sort by other columns, like memory usage (often column 4), using
ps aux | sort -k 4.
Sorting Command Output
- π¬ The
sortcommand can also sort the output of other commands, likels. - β¬οΈ To sort
lsoutput in reverse alphabetical order, usels | sort -r.
Knowledge graph15 entities Β· 10 connections
How they connect
An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.
Hover Β· drag to explore
15 entities
Chapters2 moments
Key Moments
Transcript22 segments
Full Transcript
Topics12 themes
Whatβs Discussed
Linuxsort commandTerminalAlphabetical SortNumerical SortReverse SortRemove DuplicatesSort by ColumnPiping Commandsps commandls commandCommand Line Interface
Smart Objects15 Β· 10 links
ProductsΒ· 3
ConceptsΒ· 11
LocationΒ· 1