uniq
Report or omit repeated lines in sorted input.
Synopsis
uniq [OPTION]... [INPUT [OUTPUT]]
Examples
sort file.txt | uniq
sort file.txt | uniq -c | sort -rn
uniq -d sorted.txt
sort -f file.txt | uniq -i
Common options
| Flag | Description |
|---|---|
| -c | Prefix lines with occurrence count |
| -d | Only print duplicate lines |
| -u | Only print unique lines |
| -i | Ignore case when comparing |
About uniq
The `uniq` command report or omit repeated lines in sorted input. Text viewing and editing commands are fundamental tools in any Linux user's toolkit.
Linux treats almost everything as a file, so the ability to quickly inspect, filter, transform, and edit file contents from the command line is critical. These commands are regularly combined with pipes and redirects to build powerful data-processing pipelines.
The command accepts 4 commonly used flags shown above, though the full set of options is available in the man page (`man uniq`). The 4 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.
Related commands
More File Viewing & Editing Commands
Other commands in the File Viewing & Editing category