Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

 users

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

share|improve this question

2 Answers 2

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.