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:

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

But if you use -g with -n option, you can see not the group id, but its name:

ubuntu$ id -gn greys

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

See also:

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS