tags:

views:

44

answers:

1

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 to translate a group name into a gid?

+3  A: 

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"]> 
John Ledbetter
That's the ticket. Thanks!
Wayne Conrad