How to identify what Unix groups are available on your system

Today, I’d like to answer one of the oldest questions I have in my incoming UnixTutorial questions  email folder. Please leave comments if you need any more help with researching Unix groups on your system.

How to confirm what Unix groups are available

If you remember, a while ago I’ve introduced you to the getent command. It’s a great way of querying various information databases about your systems’ users, groups and some other objects. Here’s how you would use the command to get a full list of Unix groups known to your system:

ubuntu# getent group
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
kmem:x:15:
dialout:x:20:
fax:x:21:
...

This is an abridged output, but I hope you get the idea. This output helps you confirm the following:

  1. Unix group name – first field
  2. Unix group ID (gid) – third field
  3. All the usernames of members for various groups – fourh field, unfortunatelly empty for all the groups in my example.

How to confirm the members of a Unix group

Using the same getent command, you can query the groups database using a group name. In my example below, I’m confirming the membership of a mygroup Unix group:

ubuntu# getent group mygroup
mygroup:x:1002:user1,greys,user2
As you can see, mygroup has 3 users: user1, greys and user2.

How to determine the number of Unix groups known to your system

One more thing you can learn about your Unix groups using getent command is to confirm the overall number of Unix groups – some scenarious require you to have this number. Here’s how you would use getent together with the wc command to confirm the number of groups:

ubuntu# getent group | wc -l
62
That’s it for today, let me know if there’s anything else you’d like to learn about this topic!

See also: