• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

sort: command not found

by admin

The sort command is used to sort the lines of a text file in ascending or descending order, or sort as per a specified key. The sort command arranges the lines in a file. Common sort command options are provided in the table.

Option Description
-k{column numbers} Specify field values. For example, -k2 indicates the second field.
-n Compare and sort lines based on the string numerical value.
-r Sort fields in descending order. By default, the fields are sorted in ascending order.
-t{delimiter} Separate one field from another.

If you encounter the below error while running the sort command:

sort: command not found

you may try installing the below package as per your choice of distribution:

Distribution Command
OS X brew install coreutils
Debian apt-get install coreutils
Ubuntu apt-get install coreutils
Alpine apk add coreutils
Arch Linux pacman -S coreutils
Kali Linux apt-get install coreutils
CentOS yum install coreutils
Fedora dnf install coreutils
Raspbian apt-get install coreutils

Syntax

The syntax of the sort command is:

# sort [options] {file names}

sort Command Examples

1. Sort a file in ascending order:

# sort path/to/file

2. Sort a file in descending order:

# sort --reverse path/to/file

3. Sort a file in case-insensitive way:

# sort --ignore-case path/to/file

4. Sort a file using numeric rather than alphabetic order:

# sort --numeric-sort path/to/file

5. Sort `/etc/passwd` by the 3rd field of each line numerically, using “:” as a field separator:

# sort --field-separator=: --key=3n /etc/passwd

6. Sort a file preserving only unique lines:

# sort --unique path/to/file

7. Sort a file, printing the output to the specified output file (can be used to sort a file in-place):

# sort --output=path/to/file path/to/file

8. Sort numbers with exponents:

# sort --general-numeric-sort path/to/file

Filed Under: Linux

Some more articles you might also be interested in …

  1. CentOS / RHEL : How to configure a user account to never expire (disable password ageing)
  2. CentOS / RHE 7 : How to Prevent Users from Using the Last 10 Passwords
  3. How to Set Proxy Settings on Linux command line or Terminal
  4. How to Check CentOS Version
  5. free Command Examples in Linux
  6. Understanding Samba utilities – nmblookup, smbstatus, smbtar, testparm, wbinfo, smbget
  7. UNIX / Linux : How to install and configure mutt
  8. How to Increase the File Download Size Limit in Apache
  9. megatools-dl Command Examples in Linux
  10. ledctl: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright