开发者

API to translate group name to group id (gid)

开发者 https://www.devze.com 2022-12-31 14:56 出处:网络
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 开发者_

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

精彩评论

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