Bash 5 reference · Text and System Tools

uniq (Linux command)

Remove or count adjacent duplicate lines; sort first, then use -c to count occurrences or -d to show only duplicates.

Bash 5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

uniq [-c] [-d] [-u] [FILE]

Parameters

ParameterDescription
-c Prefix lines with counts.
-d / -u Only duplicated / only unique lines.

Examples

Count occurrences
printf '/a\n/b\n/a\n/a\n' | sort | uniq -c | sort -rn

Output

      3 /a
      1 /b

Run this on your computer — see “Get Started” for setup.

Show duplicates
printf 'x\nx\ny\n' | uniq -d

Output

x

Run this on your computer — see “Get Started” for setup.

Was this page helpful?