How to use the uniq command: 2-Minute Linux Tips

Hi, this is Sandra Henry-Stocker, author of
the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at the uniq command. It’s a command that’s
very useful when you want to reduce or summarize information. Let’s say we want to see who
is logged into one of our servers. We can use a command like this, but uniq isn’t
adding any value because every line of output from who is going to be unique:
Introduce awk into the mix, we can select just the
first column of data and get a list of unique logins:
$ who | awk ‘{print $1}’ | sort | uniq jdoe
shs Note that the sorting is still important because
uniq will only count as identical lines that are both the same and in succession. Without
the sort, you could get output like this:
Now let’s add uniq’s -c (counting) option to get a by-user count of those logins:
That’s your Linux tip for uniq. If you have questions or would like to suggest a topic,
please add a comment below. And don’t forget to subscribe to the IDG Tech(talk) channel
on YouTube. If you liked this video, please hit the like
and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and

1 Comment

  1. THANK YOU SO VERY MUCH! i have been searching for this command! if i had money i would send it to you. im trying to build motherboards and possibly an os system for linux due to the UEFI which makes mother boards unable to be used by linux. needless to say im subscribed!

Leave a Reply

Your email address will not be published. Required fields are marked *