<分区>
如何在 mac os 或 linux 中获取组的组 ID?
即,Command GroupName ==> 应该返回 groupid
例如:
Command staff ==> 20
<分区>
如何在 mac os 或 linux 中获取组的组 ID?
即,Command GroupName ==> 应该返回 groupid
例如:
Command staff ==> 20
最佳答案
在 Linux 上,您可以使用 getent(1) :
$ getent group staff
staff:x:20:
如果你只想要 20 个:
$ getent group staff | cut -d: -f3
20
在 OS X 上,您可以使用 dscl(1) :
$ dscl . -read /Groups/staff | awk '($1 == "PrimaryGroupID:") { print $2 }'
20
使用这个简单的 python 命令(使用 grp library )可以更容易地在两个平台上获得相同的结果:
$ python -c 'import grp; print grp.getgrnam("staff").gr_gid'
20
关于linux - 在 mac 或 linux 中获取组名的 groupid 的命令是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10910096/