uniq

Filter or count adjacent duplicate lines in sorted input.

low risk

interactive breakdown — edit the command and press Explain
$ 
What it does

uniq removes or counts duplicate lines, but only works on adjacent duplicates — always sort first. Combined with sort | uniq -c | sort -rn, it produces frequency counts of any text data.

Common flags
FlagMeaning
-c --countPrefix lines with occurrence count
-d --repeatedPrint only duplicate lines
-u --uniquePrint only unique lines
-i --ignore-caseIgnore case when comparing
Examples
sort access.log | uniq -c | sort -rn | head -10Top 10 most frequent log lines · explain & risk-check →
sort ips.txt | uniq -dShow IPs that appear more than once · explain & risk-check →
sort errors.log | uniq -uShow lines that appear exactly once · explain & risk-check →
Pro tip

The pattern `sort | uniq -c | sort -rn` is one of the most powerful one-liners in DevOps — use it to analyze access logs, error frequencies, or any text data.

Related
sort grep awk
Open the full explainer →More in Text Processing

Reference text is hand-written and may be incomplete — check man uniq for your version. Test destructive commands on a non-production system first.