Bash 5 reference · Text and System Tools
uniq (Linux command)
Remove or count adjacent duplicate lines; sort first, then use -c to count occurrences or -d to show only duplicates.
Bash 5
Syntax
uniq [-c] [-d] [-u] [FILE]
Parameters
| Parameter | Description |
|---|---|
-c |
Prefix lines with counts. |
-d / -u |
Only duplicated / only unique lines. |
Examples
printf '/a\n/b\n/a\n/a\n' | sort | uniq -c | sort -rn
Output
3 /a
1 /bRun this on your computer — see “Get Started” for setup.
printf 'x\nx\ny\n' | uniq -d
Output
x
Run this on your computer — see “Get Started” for setup.
Related
sort· Sort lines alphabetically, numerically, in reverse, by a key column, or with human-readable sizes; -u removes duplicates.- Bash sort, uniq, cut and tr · tutorial