Remove duplicate lines from a text file

The uniq command is used to remove duplicate lines from a text file in Linux. By default, this command discards all but the first of adjacent repeated lines, so that no output lines are repeated. Optionally, it can instead only print duplicate lines. For uniq to work, you must first sort the output.

Here is an example:

linux uniq command

To display only duplicate lines, use the -d option:

linux uniq command d option


Geek University recommends the following video course to get you started with Linux.

Geek University 2022