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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With