Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

what is $uid and $gid?

by Anonymous Monk
on Apr 22, 2003 at 03:18 UTC ( #252181=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I don't get what $uid and $gid are supposed to be set at when chownding files, it doesn't tell you anything on the chown page. $uid is probably the id you log in to the server as, that's what I'm thinking but I have no idea what $gid would be. Any help from the wise monks would be appreciated.

Replies are listed 'Best First'.
Re: what is $uid and $gid?
by dws (Chancellor) on Apr 22, 2003 at 03:40 UTC
    Perl inherited the concept of user id and group id from the Unix world, which inherited them from elsewhere. Put simply, each Unix user had a unique "user id" and a not-necessarily unique "group id". Users can belong to multiple groups. All files that the user creates are stamped with these ids. chown() changes the user id. chgrp() changes the group id.

    All Unix files have protection bits, which are set when the file is created, and can be changed by chmod().

    Protection bits include 3 3-bit fields. The bits represent "can read", "can write", and "can execute". The first field represents protections that apply to the owner of the file. The second field represents protections that apply to other users in the same group, and the third field represents the protections for "everyone else" (AKA "world"). Hence, a protection of   0750
    (protections are almost always writen in octal) means that the owner can read, write, and execute the file (the 0700 part); members of the group and read and execute the file(the 050 part), and the rest of the world can do nothing (the 0 part at the end).

    There's more to it than that, but that's the basics.

      While there might be a chgrp command in your OS, Perl does not have a chgrp() function. Perl only has a chown() function, which is used to set both the user and the group id of a file. This is because many Perl functions mimic the C library, and not the programs from /usr/bin.

      Also, there are 12 protection bits, not 9. You are forgetting the "set user id", "set group id" and the "sticky bit".


Re: what is $uid and $gid?
by Zaxo (Archbishop) on Apr 22, 2003 at 03:32 UTC

    The uid is the user id number, gid the group id number. Those are unique numbers associated with the user and group names in /etc/passwd and /etc/groups.

    See getpwent and friends for how to deal with those properly in perl.

    After Compline,

Re: what is $uid and $gid?
by tstock (Curate) on Apr 22, 2003 at 03:29 UTC
    GID is group ID
    In perl 5.8.0 it says:
    chown LIST Changes the owner (and group) of a list of files.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://252181]
Approved by dorko
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2017-12-17 12:37 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (464 votes). Check out past polls.