Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With help of the who command we can get active users, I want only the first field such as

user 1
user 2
user 3
share|improve this question
up vote 18 down vote accepted

You can get just the user names like so:

who | awk '{print $1}' | sort | uniq

Where who lists all logged in users, passes the output to awk which only prints the first section ("column") of text for every line, passes it to sort which sorts the output and passes it to uniq which removes duplicates.

share|improve this answer
Or use sort -u instead of sort | uniq – DK Bose Feb 26 '14 at 11:00
Ok, did not know about that option. (Or knew and forgot!) – Stabledog Feb 26 '14 at 12:52
You don't need to use awk: who | cut --delimiter=' ' --field=1 | sort --unique (the short version reads: who|cut -d' ' -f1|sort -u). – Paddy Landau Mar 4 '14 at 22:49
Unix always provides so many ways to skin a cat. Its amazing any cats still have fur. – Stabledog Mar 5 '14 at 2:56
@PaddyLandau Why not put your answer in its own answer? – AmanicA Mar 6 '14 at 23:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.