18

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
27

You can get just the user names like so:

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

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.

5
  • 6
    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
  • 2
    You don't need to use awk: who | cut --delimiter=' ' --field=1 | sort --unique (the short version reads: who|cut -d' ' -f1|sort -u). Mar 4 '14 at 22:49
  • 1
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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