Compare

sort vs uniq

When sorting is enough and when uniq is the right follow-up for duplicate handling.

`sort` orders lines. `uniq` filters or counts adjacent duplicate lines. They are often used together, but they solve different parts of text processing.

Use sort When

You need deterministic ordering before inspection or further processing.

You want to group equal values together so later tools can operate on them reliably.

Use uniq When

You want to collapse, count, or isolate adjacent duplicate lines.

You already have input grouped or sorted so duplicates are next to each other.

Rule of Thumb

sort organizes. uniq deduplicates adjacent lines.

Want the short version? Browse the compact sheet views and save the commands you use most into a Cheatbook.