Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Is there a command to list all Unix group names?

I know there is the /etc/group file that rundowns all clients gatherings.

I might want to know whether there is a basic command to list all user bunch names despite parsing the world discernible /etc/group file. I'm willing to make an administrator website page that rundowns Linux records' group names.
by

2 Answers

ninja01
If you want all groups known to the system, I would recommend using getent group instead of parsing /etc/group:

getent group

The reason is that on networked systems, groups may not only read from /etc/group file, but also obtained through LDAP or Yellow Pages (the list of known groups comes from the local group file plus groups received via LDAP or YP in these cases).

If you want just the group names you can use:

getent group | cut -d: -f1
kshitijrana14
On Linux, macOS and Unix to display the groups to which you belong, use:
id -Gn

which is equivalent to groups utility which has been obsoleted on Unix (as per Unix manual).
On macOS and Unix, the command id -p is suggested for normal interactive.
Explanation of the parameters:
-G, --groups - print all group IDs
-n, --name - print a name instead of a number, for -ugG
-p - Make the output human-readable.

Login / Signup to Answer the Question.