GO KALI FREE
Search Commands

sort Linux Command

Sorts lines of text files alphabetically or numerically.

What does sort do?

Sorts lines of text files alphabetically or numerically.

Syntax

sort [options] file

Practical example

sort -n numbers.txt

Questions about sort

How do I sort a file alphabetically?

Use `sort filename` to sort lines alphabetically (default behavior). Lines are sorted in ascending order by default.

How do I sort numbers numerically?

Use `sort -n filename` to sort numerically. Without `-n`, sort treats numbers as text (e.g., 10 comes before 2).

How do I sort in reverse order?

Use `sort -r filename` to sort in reverse (descending) order. Combine with `-n` for numeric reverse sort.

How do I sort by a specific column?

Use `sort -k2 filename` to sort by the second column. Use `-k1,3` to sort by columns 1 through 3.

How do I remove duplicate lines while sorting?

Use `sort -u filename` to sort and remove duplicates. Or pipe to `uniq`: `sort filename | uniq`.

How do I sort by file size?

Use `ls -lS` to sort by file size, or `du -h | sort -hr` to sort directory sizes.

How do I sort case-insensitively?

Use `sort -f filename` to ignore case when sorting. 'Apple' and 'apple' will be treated as equal.

How do I sort and count duplicates?

Use `sort filename | uniq -c` to sort and count occurrences of each unique line.

Related Search Commands

sed

Stream editor for filtering and transforming text (find/replace, insert, delete).

uniq

Reports or filters out repeated lines in a sorted file.

awk

Powerful text processing language for pattern scanning and data extraction.

cut

Extracts specific columns/fields from each line of a file.

type

Displays how a command name would be interpreted (alias, builtin, external, etc.).

tr

Translates, deletes, or squeezes characters from standard input.