Piter Parker Piter Parker - 2 months ago 20
Linux Question

How to extract the UID info using grep?

I need to get the user name from

/proc/*/status
but

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


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

Answer

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