How To Find Out User ID in Unix

There's quite a few ways to confirm a user ID (uid) in Unix.

id command

This is probably one of the easiest ways to find out a uid of a particular user in your system:

# id -u greys
500

The most common way of using the id command is even simpler, and it gives you all the information about a user you may need:

# id greys
uid=500(greys) gid=500(greys) groups=500(greys)

This not only shows you the user id (uid), but also confirms user's group id (gid) and all the rest Unix groups a user belongs to.

getent

Another way to get information about a user (including uid) is to use the getent command:

# getent passwd greys
greys:x:500:500:Gleb Reys:/home/greys:/bin/bash

In this example, greys is my username, 500 is the uid, and the second 500 in this line is my Unix group id (gid).

/etc/passwd file

If you know that the user you're looking at is a local user (it is created on the local Unix system of yours), you can grep for it in /etc/passwd file directly:

$ grep greys /etc/passwd
greys:x:500:500:Gleb Reys:/home/greys:/bin/bash

Please share:
  • Digg
  • del.icio.us
  • Netvouz
  • BlinkList
  • Fark
  • Furl
  • kick.ie
  • Netscape
  • Reddit
  • StumbleUpon
  • Technorati
  • YahooMyWeb

5 comments ↓

#1 How To Find Out Which Group a Unix User Belongs To | UNIX Tutorial: Learn UNIX on 01.30.08 at 5:55 pm

[...] ← How To Find Out User ID in Unix [...]

#2 username by uid in Unix | UNIX Tutorial: Learn UNIX on 05.29.08 at 12:38 pm

[...] Thanks for visiting!Finding out the username by user id (uid) in Unix is not as common a task as determining the uid by a username, but if you need to do it – I'll show you [...]

#3 What to do if numeric id is shown instead of Unix username | UNIX Tutorial: Learn UNIX on 01.06.09 at 11:50 am

[...] Try other Unix systems in your environment It can be the case that Unix account was a local one automatically created by your system administrators. There's still a chance the same uid exists on other systems. Log into a few of them and verify if they have a user with the same user id (read this post for more information: How to Find Out user id): [...]

#4 ACEGOODFELLAS on 04.16.09 at 8:38 am

i got a couple of questions maybe some one can help…

1) find all logged-in user's with usernames of at least four characters.

2) find all users on your system whose user ids are greater than 99.

3) find the number of users on your system whose user ids are greater than 99

4) list all the files in your directory in decreasing order of file size .

plz help i tried everything i even google it and i couldnt find anything ….

#5 Nirmal on 04.28.09 at 4:28 pm

To list all the files in a directory in decreasing order of file size:

ls -al|grep -v '^d'|sort +4r

Leave a Comment