$ uniq
Report or omit repeated lines
DOCUMENTEDSearch & textUbuntu 24.04 LTS baseline
Synopsis
uniq [OPTION]... [INPUT [OUTPUT]]
What it does
- `uniq` compares adjacent lines; it does not generally remove duplicates that are separated by other lines.
- Sorting first is a common way to group identical lines together.
Examples
Remove adjacent duplicate lines
sort names.txt | uniqCount adjacent duplicate lines
sort names.txt | uniq -cImportant details
These examples are intentionally conservative. Command behavior can still depend on filesystem state, permissions, locale, shell, installed package version, and other system configuration.
For exact option semantics, the linked authoritative documentation is the source of truth.