stacktrace2234
stacktrace2234

Reputation: 179

Linux bash: how to list every logged in user, but every user should be shown only once?

At the moment I am trying with the:

w --no-header

but it lists the same user twice:

myuser tty7
myuser pts/0

How to make it to give me back only once?

It should be simply

myuser

Thanks in advance

Upvotes: 0

Views: 93

Answers (1)

Jens
Jens

Reputation: 72629

If you filter for just the first column, then sort/uniq, you would use

w --no-header | awk '{print $1}' | sort -u

Put it in a shell function and there you go.

Upvotes: 1

Related Questions