Jam*_*r P 11 bash ps shell-script
我如何创建一个脚本来计算每个用户在ps aux. 我用过这个
ps aux | awk '{print $1}' | grep root | wc -l
Run Code Online (Sandbox Code Playgroud)
但它只列出了 root 用户的数量。我想列出每个用户的进程数。我需要这样的东西:
root 20
jamshi 15
Run Code Online (Sandbox Code Playgroud)
ste*_*eve 19
ps -fo user | sort | uniq -c 值得一试。
该命令ps -eo user=|sort|uniq -c将按用户列出进程计数。
ps -eo user=|sort|uniq -c
2 avahi
1 kernoops
1 messagebus
1 nobody
231 root
1 statd
5 steve
1 syslog
Run Code Online (Sandbox Code Playgroud)
如果需要翻转要读取的列顺序,请将其通过管道 awk '{ print $2 " " $1 }'