Forrest logo
tool overview
On this page you find all important commands for the CLI tool sort. If the command you are looking for is missing please ask our AI.

sort

The sort command line tool is used to sort the lines of a file or standard input by a specific criteria. It is commonly used to arrange data in ascending or descending order based on alphabetical or numerical values.

By default, the sort command sorts the lines of a file in ascending order based on the ASCII values of the characters. It can also sort files in reverse order using the -r option.

The sort command can handle large files efficiently with the help of external sorting techniques, which involve storing temporary data on disk.

It supports various options, such as -n for sorting numerically, -u for eliminating duplicate lines, and -k for sorting based on specific columns or fields.

Additionally, the sort command can ignore leading spaces or blank characters using the -b option, and it can perform case-insensitive sorting with the -f option.

The sort command can be used in conjunction with other commands through pipes to manipulate and process data. For example, it can be combined with the uniq command to sort and remove duplicate lines.

The sort command is available on most Unix-like operating systems, including Linux and macOS. It is also supported in Windows PowerShell and Windows Subsystem for Linux (WSL).

The output of the sort command can be redirected to a new file using the > symbol or appended to an existing file using the >> symbol.

The sort command allows customization through environment variables, such as LC_ALL for specifying the language and locale settings for sorting, and LC_COLLATE for specifying the collation order.

Overall, the sort command is a versatile and powerful tool for sorting and organizing data in the command line environment.

List of commands for sort:

  • sort:tldr:0678f sort: Sort a file preserving only unique lines.
    $ sort --unique ${filename}
    try on your machine
    explain this command
  • sort:tldr:58874 sort: Sort a file using numeric rather than alphabetic order.
    $ sort --numeric-sort ${filename}
    try on your machine
    explain this command
  • sort:tldr:61ea9 sort: Sort a file in ascending order.
    $ sort ${filename}
    try on your machine
    explain this command
  • sort:tldr:7dc78 sort: Sort a file, printing the output to the specified output file (can be used to sort a file in-place).
    $ sort --output=${filename} ${filename}
    try on your machine
    explain this command
  • sort:tldr:c260b sort: Sort a file in descending order.
    $ sort --reverse ${filename}
    try on your machine
    explain this command
  • sort:tldr:da83e sort: Sort `/etc/passwd` by the 3rd field of each line numerically, using ":" as a field separator.
    $ sort --field-separator=${:} --key=${3n} ${-etc-passwd}
    try on your machine
    explain this command
  • sort:tldr:df82b sort: Sort a file in case-insensitive way.
    $ sort --ignore-case ${filename}
    try on your machine
    explain this command
  • sort:tldr:e25cf sort: Sort numbers with exponents.
    $ sort --general-numeric-sort ${filename}
    try on your machine
    explain this command
  • uniq:tldr:21d52 uniq: Display number of occurrences of each line, sorted by the most frequent.
    $ sort ${filename} | uniq -c | sort -nr
    try on your machine
    explain this command
  • uniq:tldr:90d6c uniq: Display only duplicate lines.
    $ sort ${filename} | uniq -d
    try on your machine
    explain this command
  • uniq:tldr:99184 uniq: Display only unique lines.
    $ sort ${filename} | uniq -u
    try on your machine
    explain this command
  • uniq:tldr:e90e6 uniq: Display each line once.
    $ sort ${filename} | uniq
    try on your machine
    explain this command
  • uniq:tldr:f0c2a uniq: Display number of occurrences of each line along with that line.
    $ sort ${filename} | uniq -c
    try on your machine
    explain this command
tool overview