man.lsPlain-English help for Unix commands

uniq Report or filter repeated lines

Collapses repeated lines into one, or counts them. It only compares lines that are next to each other, so it is almost always used after sort. Reach for it to count how often each value appears.

Synopsis

uniq [OPTION]... [INPUT [OUTPUT]]

Common options

Option or formWhat it does
-cPut the number of times each line occurred in front of it
-dShow only lines that appear more than once, one copy of each
-uShow only lines that appear exactly once
-iIgnore case when comparing lines
-f numSkip the first num whitespace-separated fields on each line when comparing
-s charsSkip the first chars characters on each line when comparing

Examples

Remove repeated neighbouring lines
uniq words.txt
pear
apple
pear
fig
apple
Remove all duplicates (sort first)
sort words.txt | uniq
apple
fig
pear
Count how often each word appears
sort words.txt | uniq -c
Most common words first
sort words.txt | uniq -c | sort -rn
Show only the words that appear more than once
sort words.txt | uniq -d
apple
pear
Show only the words that appear once
sort words.txt | uniq -u
fig

Notes

See also

Last reviewed 2026-10-07.