The -u option in the sort command is used to sort the input and output only the unique lines, effectively removing any duplicate lines from the result. When you use -u, the command will only display one instance of each line, even if that line appears multiple times in the input.
Example
Assuming you have a file named data.txt with the following content:
apple
banana
apple
cherry
banana
date
If you run the command:
sort -u data.txt
The output will be:
apple
banana
cherry
date
Explanation
sort -u data.txt: This command sorts the lines indata.txtand removes duplicates, displaying only unique lines in the sorted order.
Using the -u option is a convenient way to both sort and filter out duplicate entries in one step.
