API for translating group name into group identifier (gid)

File.chown

takes an owner id, a group id (gid), and a filename. I want to use it to install a gid file, but I have a group name. Is there anything in the standard library that I can use to translate the group name into gid?

+2


a source to share


1 answer


I'm not very familiar with ruby, but the syscall for Linux is struct group* getgrnam(const char* name)

AND is derived from a file /etc/group

.

According to this site, you can find this function in the module Etc

:



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

      

+4


a source







All Articles