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

Man Pages for commands in this post »

id
groups

7 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

Comment by Richard

September 3, 2013 @ 3:40 pm

This is not helpful to this newbie. I’ve spent over an hour trying to take ownership of a folder (a backup of my website). All the advise tells me to use chown or chmod or somesuch but in the command syntax I have to type my name followed by a colon and then the “usergroup” to which I belong (plus the path to the folder, but that’s another problem). If I type “group” as recommended, I get a long list of groups to which I belong. So which one am I? Which one should follow the colon? What if I type “richard:cd” since the “usergroup” command lists “cd” as one group to which I belong? Why not the other 5 or 6 “groups” the “group” command yields?

Comment by TheLinuxBlog.com

September 3, 2013 @ 5:36 pm

Sorry you did not find value.

It depends on the distribution you are on. If the backup of your website was done by another user such as root, you’ll need to use root to change ownership.

ls -alh will list the current user / group the folder belongs to. groups lists the groups you belong to, there should be a user group with the same name as your user, meaning you can just sudo chown user:user -R (R for recursive.)

I have seen some distributions / chown commands that do not like the : though. You wouldn’t use cd or another group because that means anyone in that group, would be able to perform actions that you specify, look into chmod for that.

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>