Piter Parker Piter Parker - 1 year ago 109
Linux Question

How to extract the UID info using grep?

I need to get the user name from


cat $i/status|grep "^Uid"|awk '{printf "%4s",$2}'

only display the number, instead of that I need the name, if it's
I need to display root.

Answer Source

You are almost there. Use getent for resolving UID to username:

getent passwd `grep "^Uid" /proc/$i/status |awk '{printf "%4s",$2}'`| cut -d: -f1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download