Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to find the number of groups assigned to a user in linux?

 as of right now i have:
 foo : foo bar apple users

An app I use may have given a user a group of "apple users" but I cant tell and when i ran

 groups foo | awk {print $6}

I received


I'm lost on how do find out how many users I have

share|improve this question
up vote 1 down vote accepted

As groups returns a list of groups your account is in, you can use the following:

groups | wc -w

The wc -w will count the number of words returned by groups.

share|improve this answer

The groups command does not account for groups with spaces in its output. So a group with a space in the name is output the same as two separate groups.

I would do it this way:

 grep "apple users" /etc/group

This should return something like

 apple users:x:1010:fred,barney,dino
share|improve this answer
Although I appreciate this answer, I had lookd in /etc/groups and "apple users" was not there. It is a group assigned by centrifydc. Thank you! – Cole Busby Jun 7 '13 at 17:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .