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"]>
精彩评论