Skip to main content

Command referenceuniq

uniq command (Linux / bash / sh / zsh)

Linuxbashshzshtextbeginner

What it does

Report or remove adjacent duplicate lines. When people search for the uniq command linux duplicates, they usually want uniq's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.

Report or remove adjacent duplicate lines.

Syntax

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

Common options

Flag / optionMeaning
-cPrefix lines with occurrence counts.
-dPrint only repeated groups.
-uPrint only nonrepeated groups.
-iIgnore case when comparing.

Practical examples

Remove duplicates

sort names.txt | uniq

Collapses equal adjacent names.

Count values

sort events.txt | uniq -c

Counts each grouped event line.

Repeated only

sort ids.txt | uniq -d

Prints IDs appearing more than once.

Common mistakes

  • Running uniq on unsorted data and expecting all duplicates to disappear.
  • Confusing `-u` unique-only output with normal deduplication.

FAQ

What does uniq do in Linux?

Report or remove adjacent duplicate lines.

How do I use uniq from the terminal?

Start with `uniq [OPTION]... [INPUT [OUTPUT]]`, then choose only the options needed for the task.

What is a practical uniq example?

Try `sort names.txt | uniq` — Collapses equal adjacent names.

Can I use uniq in a shell script?

Yes. uniq works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.