127

The title says it all. What command I need to run from a terminal to find my user ID (UID)?

171

There are a couple of ways:

  1. Using the id command you can get the real and effective user and group IDs.

    id -u <username>
    

    If no username is supplied to id, it will default to the current user.

  2. Using the enviroment variable.

    echo $UID
    
  • 2
    How about GID ? – kangear Oct 29 '15 at 1:11
  • 6
    @kangear id -g <username> – itsazzad Dec 18 '15 at 15:23
  • It's worth noting that, due to the fact that the variables are resolved before being passed to a command, we have that sudo echo ${UID} prints out 1000 (or whatever your sudoer user's UID is), whereas sudo id -u prints out 0. – AnthonyD973 Dec 19 '18 at 20:33
38

Simply try

id

This will return your user ID, group ID, and all your groups.

  • 7
    or id -u to see just the UID – steeldriver May 17 '14 at 13:21
  • Yepp. Prefer Jobin's answer, if you need to avoid parsing the output. – TAq May 17 '14 at 13:25
  • so much easier with id -u and id -g. Thanks. :) – thoroc Aug 3 '17 at 17:00
10

Try also :

getent passwd username

This will display user id , group id and home directory .

Or:

grep username /etc/passwd
  • why to try long or alternative command while echo $UID and id -u is simple and exact according to question? – Pandya May 17 '14 at 13:37
  • 3
    thats right , but its good to know all options – nux May 17 '14 at 13:38
8

You can use id command.

Manpage

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.