Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
5  
Use echo $UID? –  Louis Matthijssen May 17 at 13:17
1  
TAq's or Jobin's answer may be better. :) –  Louis Matthijssen May 17 at 13:21
add comment

4 Answers 4

up vote 13 down vote accepted

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
    
share|improve this answer
add comment

Simply try

id

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

share|improve this answer
1  
or id -u to see just the UID –  steeldriver May 17 at 13:21
    
Yepp. Prefer Jobin's answer, if you need to avoid parsing the output. –  TAq May 17 at 13:25
add comment

Try also :

getent passwd username

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

Or:

grep username /etc/passwd
share|improve this answer
    
why to try long or alternative command while echo $UID and id -u is simple and exact according to question? –  Pandya May 17 at 13:37
2  
thats right , but its good to know all options –  nux May 17 at 13:38
add comment

You can use id command.

Manpage

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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