开发者

API to translate group name to group id (gid)

File.chown takes an owner ID, a group ID (gid), and a filename. I want to use it to set a file's gid, but what I have is the group name. Is there anything in the standard library that I can use 开发者_Python百科to translate a group name into a gid?


I'm not overly familiar with ruby, but the Linux syscall for this is struct group* getgrnam(const char* name) And is obtained from the /etc/group file.

According to this site you can find this functionality in the Etc module:

Etc.getgrnam(‘users’) -> 
    #<struct Struct::Group
             name="users",
             passwd="x",
             gid=100,
             mem=["meta", "root"]> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜