Linux Blog

What groups am I in?

Filed under: Quick Linux Tutorials — TheLinuxBlog.com at 10:45 am on Tuesday, April 21, 2009

@nongeekboy on Twitter tweeted? about a blog post: Simple Script To List Groups in passwd File. I read it and have done something similar before so I figured I’d blog it here so I won’t have to write it again. Anyway, along with the point of this post, since this is suppose to be quick.

A question that is often asked is “What groups am I in?”

The easiest way to find out is to type the command: groups
This will give you a list of the groups you are in separated by a space. There are some other fancy ways of getting the groups but they rely on the `id` command. Running groups with no user name, its the same as running id -Gn.

Here are some other variations that you can try if you need to script the output:

1
2
3
4
5
6
7
8
9
groups
id
id -G
id -g
id -n
id -nG [user]
and the obvious:
id --help
info id

Related Posts

Man Pages for commands in this post »

id
groups

5 Comments »

Comment by Neal Pointer

April 22, 2009 @ 9:35 am

Been using Unix over 15 years, and never new the id command. Mind you, never had a situation where i’d need to know my userid or my group. Its always be my name or root, and the groups was always users.

Comment by Clayton

April 22, 2009 @ 9:23 pm

What about just “groups”. That outputs just a straight space-delimited listing of all your groups (without the group ID, however).

Comment by TheLinuxBlog.com

April 23, 2009 @ 8:43 am

@CLAYTON Yea I didn’t think of adding that one in there. I’ve updated the “variations” list. Thanks!

Comment by Clayton

April 23, 2009 @ 4:28 pm

No problem, I didn’t really think about those other variations. Thanks for those!

Comment by Tom Vernon

February 24, 2010 @ 8:56 am

Useful, I didn’t even know the id command existed!

You can also use lid to find which users are in a group or which groups a user is in:

lid username
lid -g groupname

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>