Skip to content

uniq command

Remove or count repeated adjacent lines.

On this page

Syntax

uniq [options] [input [output]]

Provided by the coreutils package. Run man uniq for the full manual.

Common options

OptionWhat it does
-cPrefix each line with its count
-dOnly print duplicated lines
-uOnly print unique lines
-iIgnore case

Examples

  1. Remove duplicates (sort first)

    sort list.txt | uniq
  2. Count occurrences

    sort list.txt | uniq -c
  3. Most common lines first

    sort access.log | uniq -c | sort -rn | head
  4. Only lines that repeat

    sort list.txt | uniq -d

Tips

  • uniq only compares neighbouring lines, so sort the input first.

← All Linux commands · Suggest a fix

Back to top