id – print Unix user identity
id command is one of the basic unix commands, and it servers a very simple purpose of confirming the identity of a specified Unix user.
Simplest way to use the id command
All you do is just type id in your command line prompt, and it then gets back to you with confirmations of your own user id, group id, and a list of other groups you’re a member of:
Identity of a Unix user
Just as easily, you can specify a username to find out similar information. In this example, we’re confirming the identity of the privileged uset, root:
Creative ways of using the id command
id command has a few command line options which are particularly useful in shell scripting. While the default use (see above) gives you all the information, you can use options to get only the part of user identity which interests you.
Unix user primary (effective) group
Using -g parameter, you can confirm the primary Unix group of any user. Used alone, this option returns you a Unix group id:
But if you use -g with -n option, you can see not the group id, but its name:
All the unix groups a user belongs to
In a very similar way, you can use -G parameter to show all the groups a given user belongs to. You can either get the group ids, or get id to report group names:
Unix user ID (effective userid)
If you’re just after the user id of a given user, you need to use the -u command line option:
See also
id command is one of the basic unix commands, and it servers a very simple purpose of confirming the identity of a specified Unix user.
Simplest way to use the id command
All you do is just type id in your command line prompt, and it then gets back to you with confirmations of your own user id, group id, and a list of other groups you’re a member of:
Identity of a Unix user
Just as easily, you can specify a username to find out similar information. In this example, we’re confirming the identity of the privileged uset, root:
Creative ways of using the id command
id command has a few command line options which are particularly useful in shell scripting. While the default use (see above) gives you all the information, you can use options to get only the part of user identity which interests you.
Unix user primary (effective) group
Using -g parameter, you can confirm the primary Unix group of any user. Used alone, this option returns you a Unix group id:
But if you use -g with -n option, you can see not the group id, but its name:
All the unix groups a user belongs to
In a very similar way, you can use -G parameter to show all the groups a given user belongs to. You can either get the group ids, or get id to report group names:
Unix user ID (effective userid)
If you’re just after the user id of a given user, you need to use the -u command line option: