Hel*_*hne 13
您可以尝试一些变体:
ps haux Ou | cut '-d ' -f1 | uniq -c
Run Code Online (Sandbox Code Playgroud)
它为您提供每个用户的进程数(登录与否).现在,您可以使用w命令的输出或其他确定登录方式的方法来过滤这些结果.
尝试一下:
ps -u "$(echo $(w -h | cut -d ' ' -f1 | sort -u))" o user= | sort | uniq -c | sort -rn
Run Code Online (Sandbox Code Playgroud)
为了正确处理可能超过八个字符的用户名,请使用users而不是w.后者截断用户名.
ps -u "$(echo $(printf '%s\n' $(users) | sort -u))" o user= | sort | uniq -c | sort -rn
Run Code Online (Sandbox Code Playgroud)