Hi! If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
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:
ubuntu$ id uid=1000(greys) gid=113(admin) groups=33(www-data),113(admin)
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:
ubuntu$ id root uid=0(root) gid=0(root) groups=0(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:
ubuntu$ id -g greys 113
But if you use -g with -n option, you can see not the group id, but its name:
ubuntu$ id -gn greys admin
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:
ubuntu$ id -G greys 113 33 ubuntu$ id -Gn greys admin www-data
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:
ubuntu$ id -u greys 1000











4 comments ↓
[...] id command [...]
[...] Hi! If you're new here, you may want to subscribe to the Unix Tutorial RSS feed to get regular tips & tricks for all flavors of Unix. Thanks for visiting!If you know the name of a particular user on your Unix system and just want to confirm the primary Unix group (gid) of this individual, just use the id command: [...]
[...] the username, it's very easy to use the id command to confirm the user [...]
[...] id - print user identity [...]
Leave a Comment