Beginner Package: coreutils

sort

Sort lines of text.

Syntax

sort [options] [file...]

Description

sort orders the lines of a file or input stream alphabetically, numerically or by a specific field, and is very often combined with uniq to summarise and de-duplicate data.

Examples

sort file.txt
Sort lines alphabetically
sort -n numbers.txt
Sort numerically instead of lexically
sort -k2 -t, data.csv
Sort by the second comma-separated field
sort file.txt | uniq -c
Sort then count duplicate lines

Applies to

Ubuntu Debian Linux Mint RHEL CentOS / Rocky / AlmaLinux Fedora Arch Linux openSUSE Alpine Linux

Put it into practice

Learn this in context