The id
command in Unix-like systems is used to display the user and group information for the current user or a specified user. It can display information such as the user ID (UID), group ID (GID), and the groups that the user belongs to.
Here are some examples of how to use the id
command:
- Display the user and group information for the current user:
$ id
uid=1000(user) gid=1000(user) groups=1000(user),4(adm),24(cdrom),27(sudo),46(plugdev),109(lxd)
- Display the user and group information for a specific user:
$ id user2
uid=1001(user2) gid=1001(user2) groups=1001(user2)
- Display the user and group information in a more human-readable format:
id -un
user
id -gn
user
id -Gn
user adm cdrom sudo plugdev lxd
In this example, the first id
command displays the user and group information for the current user. The second id
command displays the user and group information for the user “user2”. The last set of id
commands display the user name, group name, and group names for the current user. The -un
option displays the user name, the -gn
option displays the group name, and the -Gn
option displays a list of group names.