< Previous | Contents | Next >
uniq - Report Or Omit Repeated Lines
The uniq command is often used in conjunction with sort. uniq accepts a sorted list of data from either standard input or a single filename argument (see the uniq man page for details) and, by default, removes any duplicates from the list. So, to make sure our list has no duplicates (that is, any programs of the same name that appear in both the /bin and /usr/bin directories) we will add uniq to our pipeline:
[me@linuxbox ~]$ ls /bin /usr/bin | sort | uniq | less
[me@linuxbox ~]$ ls /bin /usr/bin | sort | uniq | less
In this example, we use uniq to remove any duplicates from the output of the sort command. If we want to see the list of duplicates instead, we add the “-d” option to uniq like so:
[me@linuxbox ~]$ ls /bin /usr/bin | sort | uniq -d | less
[me@linuxbox ~]$ ls /bin /usr/bin | sort | uniq -d | less