id – print user and group IDs

id displays user and group IDs for the current user or a specified user.
Synopsis
id [OPTIONS] [USER]
Common Options
| Option | Description |
|---|---|
-u | Print only effective user ID |
-g | Print only effective group ID |
-G | Print all group IDs |
-n | Print name instead of number |
-r | Print real ID instead of effective |
Examples
Full information
$ id
uid=1000(greys) gid=1000(greys) groups=1000(greys),27(sudo),999(docker)
Just username
$ id -un
greys
Just user ID
$ id -u
1000
Just group ID
$ id -g
1000
All groups
$ id -Gn
greys sudo docker www-data
Another user
$ id root
uid=0(root) gid=0(root) groups=0(root)
$ id www-data
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Understanding Output
uid=1000(greys) gid=1000(greys) groups=1000(greys),27(sudo),999(docker)
│ │ │
│ │ └─ All group memberships
│ └─ Primary group
└─ User ID and name
Common Patterns
Check if root
if [ "$(id -u)" -eq 0 ]; then
echo "Running as root"
fi
Check group membership
if id -nG | grep -qw docker; then
echo "User is in docker group"
fi
Tips
- id vs whoami:
idshows more info (groups, IDs) - Effective vs real: After
sudo, effective UID changes but real doesn’t - Group membership: Shows why you can/can’t access certain files
- Numeric IDs: Useful in scripts for cross-system compatibility






