Forrest logo
back to the sort tool

uniq:tldr:90d6c

uniq: Display only duplicate lines.
$ sort ${filename} | uniq -d
try on your machine

This command is used to find duplicate lines in a file.

Here's a breakdown of the command:

  1. sort: This command sorts the lines in the file alphabetically. Sorting the lines is necessary for finding duplicate lines because it brings identical lines next to each other.

  2. ${filename}: This is a placeholder for the name of the file that you want to check for duplicate lines. Replace ${filename} with the actual name of your file.

  3. |: This is a pipe symbol, used to send the output of one command as input to another command.

  4. uniq -d: uniq is a command used to filter out duplicate adjacent lines and only display unique lines. The -d option is used to instruct uniq to only show the duplicate lines.

Therefore, when you run sort ${filename} | uniq -d, it sorts the lines in the file alphabetically and then filters out and displays only the duplicate lines.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the sort tool