How to get the username if I know only the user's UID?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to get the username if I know only the user's UID?
# 1  
Old 03-10-2010
How to get the username if I know only the user's UID?

Hi,

I know the user's UID, but I need to know the user's username which has this UID. How can I do it?? Any ideas?

Thanks!
# 2  
Old 03-10-2010
Code:
$ grep 'UIDnumber' /etc/passwd

Is this OK?
# 3  
Old 03-10-2010
Quote:
Originally Posted by tukuyomi
Code:
$ grep 'UIDnumber' /etc/passwd

Is this OK?
That's OK if it's a local user (i.e. not an AD user, etc.)

I think
Code:
getent passwd

might yield more success.

i.e.
Code:
/root # getent passwd 0
root:x:0:0:root:/root:/bin/ksh

(I think it works with non-local users, etc... can't remember, need to check Smilie)
# 4  
Old 03-10-2010
Bug To find a particular UID

The uid is normally the third field in /etc/passwd. Thus, to find username for uid=1000
Code:
awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd

# 5  
Old 03-10-2010
The grep solutions could return multiple answers.
If there is a user with uid 123 and another user with uid 1123.
# 6  
Old 03-10-2010
joeyg's awk solution is in post #4 works perfectly.
# 7  
Old 03-12-2010
Yes, the awk solution in post #4 works perfectly!

Thanks a lot!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

UID & GID instead of user name and group name

Hi Everyone, We are encountering the following issue on AIX 5.3. When we do ls -ltr the list displays only user id and group id instead of user name and group name. This is happening for all users except root. Whe we do ls -ltr with root user it shows perfectly fine. When we searched... (25 Replies)
Discussion started by: madhav.kunapa
25 Replies

2. Shell Programming and Scripting

Ps - list where UID is numeric or name and for current user

Hi, 'ps -ef' returns output of the following format UID PID PPID C STIME TTY TIME CMD root 17573 1 0 Sep12 tty6 00:00:00 /sbin/mingetty tty6 hpsmh 18150 14864 0 Sep12 ? 00:00:00 /opt/hp/hpsmh/sbin/hpsmhd -DSSL -f /opt/hp/hpsmh/conf/smhpd.conf root ... (3 Replies)
Discussion started by: ysrini
3 Replies

3. UNIX for Advanced & Expert Users

UID of user accounts on *nix systems

Hi, As the /etc/passwd file contents all system and other users accounts on a linux/unix system, can anyone tell me what is the User ID values range for human user accounts (not system user accounts) on a linux (Red Hat/SuSE etc) and Unix (Solaris) OS. I heard below number 100, all users are... (2 Replies)
Discussion started by: sanzee007
2 Replies

4. Shell Programming and Scripting

Create user if UID not exist; else, exit the script

Hi, I want to write a script to check whether an user ID is used in my server and then create that user. If the user ID is not used, I will echo something like "OK, continue" and then continue to execute the script. Else, I will echo something like "Used, exit" and then exit the script. As... (4 Replies)
Discussion started by: dirkaulo
4 Replies

5. Shell Programming and Scripting

Get username of last user to modify a file

Possible to get this? Thanks (2 Replies)
Discussion started by: stevensw
2 Replies

6. UNIX for Dummies Questions & Answers

Doubt over Uid and User name.

Hi, I know the uid and I wan to know the user name the uid belongs to. How can I get it. Suppose My user name is ssnayak and coresponding uid is 1110 Similarly I know one uid 1212 and how can I come to know the user name for this uid. Thanks & Regards, Siba (3 Replies)
Discussion started by: siba.s.nayak
3 Replies

7. Shell Programming and Scripting

NIS User UID Change

Hi All, I need to change the UID numbers of many NIS users, is there any command to modify the UID in NIS maps ? ( like usermod) so that their file permissions will be same even with their new UID. If not, how to check all the files owned by particular user in a computer and change the... (1 Reply)
Discussion started by: RAA
1 Replies

8. UNIX for Dummies Questions & Answers

AIX:creating user with username more than 8 chars

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa (0 Replies)
Discussion started by: anuafs84
0 Replies

9. AIX

User ID (UID) in AIX

what is the upper limit for UID is AIX 5.3 ? (1 Reply)
Discussion started by: learner
1 Replies
Login or Register to Ask a Question