402

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

Braiam
  • 69,112
a06e
  • 14,233

5 Answers5

527

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 shell variable. (It is not an environment variable, and thus is not available in env).

     echo $UID
    
guntbert
  • 13,475
jobin
  • 28,567
125

Simply try

id

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

TAq
  • 1,401
21

Try also:

getent passwd $USER

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

Or:

grep $USER /etc/passwd
wovano
  • 115
  • 2
  • 7
nux
  • 39,152
12

Get the User ID (UID) and Group ID (GID) for the running user

id -u  # user ID (UID)
id -g  # group ID (GID)

Example run and output for the active user (myself):

$ id -u
1000
$ id -g
1000

and for the root user (via sudo):

$ sudo id -u
[sudo] password for gabriel: 
0
$ sudo id -g
0

Note that the first user is generally 1000 for both the UID and GID, and the root user is generally 0 for both the UID and GID.

Gabriel Staples
  • 11,502
  • 14
  • 97
  • 142
10

You can use id command.

Manpage