Skip to main content

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 sort command in Linux can easily sort text files alphabetically.
  • πŸš€ To sort a file named letters.txt, use the command sort letters.txt.

Reversing Sort Order

  • πŸ”„ To sort in reverse alphabetical order, add the -r option: sort -r letters.txt.
  • 🎯 This changes the order from A-Z to Z-A.

Sorting Numbers Numerically

  • πŸ”’ For numerical sorting, use the -n option: sort -n numbers.txt.
  • πŸ“ˆ This sorts numbers from smallest to largest.
  • πŸ”€ Combine -n and -r (sort -n -r numbers.txt) to sort numbers from largest to smallest.

Removing Duplicate Lines

  • πŸ—‘οΈ Use the -u option to remove duplicate lines: sort -u letters.txt.
  • πŸ’― For numbers, combine -n and -u: sort -n -u numbers.txt.
  • πŸ—„οΈ You can also combine -n, -u, and -r for reverse numerical unique sorting.

Sorting by Specific Columns

  • πŸ—‚οΈ The -k option allows sorting by a specific column.
  • πŸ’» To sort ps output by the first column (username), use ps 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 sort command can also sort the output of other commands, like ls.
  • ⬆️ To sort ls output in reverse alphabetical order, use ls | 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