How to Get User Name by uid in Linux

By | March 29, 2018

Just a short command to obtain user name, if you just know uid (may be useful if you are investigating logs that don’t include usernames).

awk -v val={uid comes here} -F ":" '$3==val{print $1}' /etc/passwd

Let’s try to search for username with uid=0:

[root@server ~]# awk -v val=0 -F ":" '$3==val{print $1}' /etc/passwd
root

Leave a Reply