开发者

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

开发者 https://www.devze.com 2023-03-20 20:08 出处:网络
how to list all of the users whom has at least one running process. The user name should not be duplicated.

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 s开发者_开发问答orted. 


$ 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号