What determines permission mask of directories created by CreateDirectory? Calling


gives directory with mask 0777 as listed by ls (on OSX)

$ ls /tmp
drwxrwxrwx  2 user  staff    68B  7 paź 22:34 dir

One can check default umask by calling e.g.

ReadList["!umask", String]


but this I'm guessing is not connected in any way to CreateDirectory. Calling Run, ReadList or RunProcess (v10) with default settings passed to mkdir gives also directory with 0777 mask. Is there any way of changing default mask used by CreateDirectory?

  • 2
    $\begingroup$ Did you try for example Run["mkdir -m u=rwx,g=,o= /tmp/dir"] ? Works for me. $\endgroup$
    – SquareOne
    Commented Oct 7, 2015 at 23:48
  • 1
    $\begingroup$ no help, but a confirmation and also note if you create a file ( Run["touch file"] ) it gets an "all rw" mask regardless of the umask setting. $\endgroup$
    – george2079
    Commented Oct 8, 2015 at 16:29

1 Answer 1


Yes, the umask is very relevant.

According to mkdir(2) system call man page (which is what CreateDirectory ultimately does),

The directory path is created with the access permissions specified by mode and restricted by the umask(2) of the calling process.

As mentioned in the question, the default mode is 0777. We can check the effect of umask -- this being OS X, it's best seen by running a standalone kernel from a terminal, so that the umask gets properly inherited from the parent process (bash).

$ umask 0123
$ WolframKernel
Mathematica 10.3.0 for Mac OS X x86 (64-bit)
Copyright 1988-2015 Wolfram Research, Inc.

In[1]:= d = CreateDirectory["/tmp/foo"];                                        

In[2]:= ReadString[StringJoin["!ls -ld ", d]]                                             

Out[2]= "drw-r-xr--  2 iliang  wheel  68 Oct 29 17:31 /tmp/foo"

(note: I used OS X 10.10 in the above example. With OS X 10.11, the result would be as if umask had not been set)

As for what happens when using the notebook interface (i.e. the kernel is launched by the frontend), there probably are ways to set a umask for GUI programs on OS X, but I wasn't really tempted to try them: SquareOne's suggestion to use something like

Run["mkdir -m u=rwx,g=,o= /tmp/dir"]

works just fine.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.