The title says it all. What command I need to run from a terminal to find my user ID (UID)?
Asked
Active
Viewed 9.8e+01k times
5 Answers
527
There are a couple of ways:
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.Using the shell variable. (It is not an environment variable, and thus is not available in
env).echo $UID
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