Filter or count adjacent duplicate lines in sorted input.
low risk
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.
| Flag | Meaning |
|---|---|
-c --count | Prefix lines with occurrence count |
-d --repeated | Print only duplicate lines |
-u --unique | Print only unique lines |
-i --ignore-case | Ignore case when comparing |
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 →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.
Reference text is hand-written and may be incomplete — check man uniq for your version. Test destructive commands on a non-production system first.