擅长:python、mysql、java
<p>见<a href="http://docs.python.org/library/grp.html#grp.getgrnam" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<blockquote>
<p><code>grp.getgrnam(name)</code></p>
<p>Return the group database entry for the given group name. KeyError is raised if the entry asked for cannot be found.</p>
<p>Group database entries are reported as a tuple-like object, whose attributes correspond to the members of the group structure:</p>
</blockquote>
<pre><code>Index Attribute Meaning
0 gr_name the name of the group
1 gr_passwd the (encrypted) group password; often empty
2 gr_gid the numerical group ID
3 gr_mem all the group member’s user names
</code></pre>
<p>数字组ID位于索引2处,或者是倒数第二个,或者属性<code>gr_gid</code>。</p>
<p><code>root</code>的GID为0:</p>
<pre><code>>>> grp.getgrnam('root')
('root', 'x', 0, ['root'])
>>> grp.getgrnam('root')[-2]
0
>>> grp.getgrnam('root').gr_gid
0
>>>
</code></pre>