Cheatsheets
HomeWriteupsResourcesCheatsheets
Linux
Linux
  • Know Yourself and Your System
    • id
    • logname
    • uname
    • w
    • who
    • whoami
  • Surfing / Knowing Your File System
    • cd
    • df
    • du
    • ls
    • pwd
    • stat
    • tree
  • Knowing About Files / Commands
    • alias
    • file
    • info
    • whatis
    • apropos
    • man
    • help
    • history
    • script
  • Manipulating Files / Directories
    • touch
    • mkdir
    • rm
    • rmdir
    • cp
    • mv
    • ln
  • Interacting with Files
    • cat
    • head
    • less
    • middle
    • more
    • tail
  • STROPS / Text Manipulation
    • awk
    • cut
    • grep
    • jq
    • join
    • paste
    • sed
    • sort
    • tr
    • uniq
    • xargs
    • xclip
    • wc
    • tee
    • echo
    • comm
    • diff
    • patch
    • aspell
    • Combos
  • Formatting the Output
    • nl
    • fold
    • fmt
    • pr
    • printf
  • Searching / Finding
    • find
    • locate
    • which
    • whereis
    • type
  • Web Interaction
    • curl
    • wget
  • xxd
  • References
Powered by GitBook
On this page
  • Introduction
  • Syntax
  • Important Flags
  • Examples

Was this helpful?

  1. STROPS / Text Manipulation

sort

sort linux command cheatsheet by Thamizhiniyan C S

Introduction

sort command, as the name suggests sorts the lines alphabetically and numerically, automatically.


Syntax

sort [OPTION]... [FILE]...


Important Flags

Flags
Description

-r

Sorts in reverse order

-c

This flag is used to check whether the file is already sorted or not(If not, it will list, where the disorder started)

-u

To sort and removes duplicate lines(does work same as stdin redirected into uniq)

-o save.txt

To save into a output file

-t

Define Field Separator

-k

Reorders data in a specific field

-n

Sorts the file numerically

-M

Sorts by month names


Examples

Command
Description

Order the lines in lexicographical order

Order the lines in reverse lexicographical order (i.e. Z-A instead of A-Z)

Sort the lines in ascending order based on numbers

Sort the lines in descending order based on numbers

Sorts lines of text based on the second field (using a numerical comparison) in reverse order, considering tab characters as the field separator

Sort lines of text based on the second field in ascending numerical order, considering tab characters as the field separator

Sort lines of text based on the second field in descending numerical order, considering '|' as the field separator.

PrevioussedNexttr

Last updated 1 year ago

Was this helpful?

sort -d
sort -r
sort -n
sort -n -r
sort -t $'\t' -k 2 -n -r
sort -t $'\t' -k 2 -n
sort -t '|' -k 2 -n -r