What is the command to get groupid of a group name in mac or linux?
linux, macos, macros
Solution
On Linux, you can use getent(1):
$ getent group staff
staff:x:20:
If you only want 20:
$ getent group staff | cut -d: -f3
20
On OS X, you can use dscl(1):
$ dscl . -read /Groups/staff | awk '($1 == "PrimaryGroupID:") { print $2 }'
20
It can be easier to use this simple python command (using the grp library) to have the same result on both platforms:
$ python -c 'import grp; print grp.getgrnam("staff").gr_gid'
20
Problem
How can I get group id of a group in mac os or linux? ie., Command GroupName ==> should return the groupid Eg: ``` Command staff ==> 20 ```