Punto has asked for the wisdom of the Perl Monks concerning the following question:

I need to do a simple task: create a directory with mode 770 (drwxrwx---). So I tried this:
mkdir("dir1", 0770); mkdir("dir2", 770); mkdir("dir3", "0770"); mkdir("dir4", "770"); mkdir("dir5", "1770"); mkdir("dir6", 1770);
And I get this:
drwxrws--- 2 punto punto 1024 Jun 20 10:39 dir1 dr----S--T 2 punto punto 1024 Jun 20 10:39 dir2 dr----S--T 2 punto punto 1024 Jun 20 10:39 dir3 dr----S--T 2 punto punto 1024 Jun 20 10:39 dir4 d-wxr-s--T 2 punto punto 1024 Jun 20 10:39 dir5 d-wxr-s--T 2 punto punto 1024 Jun 20 10:39 dir6
The closest is the firs one, but it's not exactly what I want.. What am I doing wrong?

Thanks..

Replies are listed 'Best First'.
Re: Creating a directory.
by mdillon (Priest) on Jun 20, 2000 at 05:20 UTC
    the first form is what you want. the reason that the directory is being created with g+s is most likely that its parent directory is g+s.

    i would just create it and chmod it after.

    for what it's worth, when i create a directory from the command line in a g+s parent with this command (with a umask of 002):

    mkdir -m0770 dir1

    it is created with the same permissions as the directory created by your first line of your Perl code.

RE: Creating a directory.
by merlyn (Sage) on Jun 20, 2000 at 06:08 UTC
    1. 0770 = 770 octal
    2. 770 = 770 decimal (weird bits)
    3. "0770" = 770 decimal
    4. "770" = 770 decimal
    5. "1770" = 1770 decimal (different weird bits)
    6. 1770 = 1770 decimal
    And as someone else already said, yes, the bits of the umask are cleared from this value. Either change your umask, or try a chmod afterward.

    -- Randal L. Schwartz, Perl hacker

Re: Creating a directory.
by chromatic (Archbishop) on Jun 20, 2000 at 05:34 UTC
    According to the mkdir documentation, the resulting permissions are modified by your active umask.

    When I do a mkdir with 0770 permissions, the result is a directory without group write permissions. (I have a umask of 022).

Re: Creating a directory.
by Punto (Scribe) on Jun 20, 2000 at 08:04 UTC
    I don't understand.. What is unmask? I read the documentation, but I don't get it..
      Its umask and not unmask. You can find more documentation on it by refering to the bash_builtins via the umask manpages. Try man umask on your console. Its a good doc, very yummy. I'd recommend reading it entirely. For what its worth, here's the scoop from ~ line 1450 or so.
      umask [-p] [-S] [mode] The user file-creation mask is set to mode. If mode begins with a digit, it is interpreted as an octal number; otherwise it is interpreted as a sym­ bolic mode mask similar to that accepted by chmod(1). If mode is omitted, or if the -S option is supplied, the current value of the mask is printed. The -S option causes the mask to be printed in symbolic form; the default output is an octal number. If the -p option is supplied, and mode is omitted, the output is in a form that may be reused as input. The return status is 0 if the mode was successfully changed or if no mode argu­ ment was supplied, and false otherwise.
      HTH!

      #!/home/bbq/bin/perl
      # Trust no1!
      umask, in short, says "when creating afile or directory, do NOT set the following bits that I have set in my umask". So a umask of 002 says "do not set the world WRITE bit during a create, even if they say to set it". A umask of 077 would say "never set any bits for world or group". You can go ahead and explicitly set those bits with chmod after the file is created if you want. It's just a rudimentary security tool thing ... to make sure people don't go around creating 777 files without knowing it. Most umasks only mask the world access bits, and sometimes group access bits.