Forever & AlwaysLINUX COMMAND ATLAS

LINUX COMMAND ATLAS · COMMAND GUIDE

Linux uniq command

Report or remove adjacent repeated lines; sort first to group matches.

GNU Coreutils

Syntax

Command form
uniq [OPTION]... [INPUT [OUTPUT]]

Common options

6 options
OptionWhat it does
-c, --countPrefix each output line with its number of occurrences.
-d, --repeatedPrint only repeated lines.
-u, --uniquePrint only lines that occur once.
-i, --ignore-caseIgnore case when comparing lines.
-f, --skip-fields=NSkip N fields before comparing.
-s, --skip-chars=NSkip N characters before comparing.

Usage examples

2 examples

Report or remove adjacent repeated lines; sort first to group matches.

sort names.txt | uniq -c

Print values that occur more than once.

sort names.txt | uniq -d

Notes

uniq only detects adjacent duplicate lines, so sort the input first when duplicates may be separated.