Jane_Meng
Jane_Meng

Reputation: 759

under mac terminal: List all of the users whom has at least one running process?

how to list all of the users whom has at least one running process.

The user name should not be duplicated.
The user name should be sorted. 

Upvotes: 0

Views: 1020

Answers (3)

Michael J. Barber
Michael J. Barber

Reputation: 25042

users does what is requested. From the man page:

users lists the login names of the users currently on the system, in sorted order, space separated, on a single line.

Upvotes: 1

Mihai Maruseac
Mihai Maruseac

Reputation: 21435

Try this:

w -h  | cut -d' ' -f1 | sort | uniq

The w -h displays all users in system, without header and some output. The cut part removes all other information without username. uniq ignores duplicate lines.

Upvotes: 0

Ronny Vindenes
Ronny Vindenes

Reputation: 2361

$ ps xau | cut -f1 -d " "| sort | uniq | tail -n +2

You may want to weed out names starting with _ as well like so :

ps xau | cut -f1 -d " "| sort | uniq | grep -v ^_ | tail -n +2

Upvotes: 3

Related Questions