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.
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:
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:
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.
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:
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:
If you’re just after the user id of a given user, you need to use the -u command line option: