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

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.


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

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
  • Pingback: How To Find Out Which Group a Unix User Belongs To | UNIX Tutorial: Learn UNIX()

  • Pingback: username by uid in Unix | UNIX Tutorial: Learn UNIX()

  • Pingback: What to do if numeric id is shown instead of Unix username | UNIX Tutorial: Learn UNIX()


    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 ….

  • Nirmal

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

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

  • Sandeep

    I don't know if you stiill need these answers….anyways here are the answers

    1) who |cut -d: -f1|grep '[a-zA-Z0-9]\{4,\}'
    2) cat /etc/passwd |cut -d: -f3|grep '[0-9]\{3,\}'
    3) cat /etc/passwd |cut -d: -f3|grep '[0-9]\{3,\}'|wc -l
    4) ls -alS|grep -v '^d'

    hope this helps

  • unix_god

    umm to list files in decreasing size order that wont work for a couple reasons, what if the size is Mb and Gb? and 1Gb will show as smaller than 450Mb… simply use
    ls -laSh