How can I create a directory with normal permissions (say 0700 in octal notation) with the os.Mkdir
method. I did not manage to find how to set the perm
value correctly.
Asked
Active
Viewed 4,368 times
4

user983716
- 1,992
- 1
- 22
- 32
-
Possible duplicate here: http://stackoverflow.com/q/14249467/395461 – Shannon Matthews Jul 23 '15 at 04:18
1 Answers
8
You can use that octal notation directly:
os.Mkdir("dirname", 0700)
From the documentation for FileMode:
The nine least-significant bits are the standard Unix rwxrwxrwx permissions
The mode bits are defined so that you may use normal octal notation just as you would with chmod. However, you must prefix it with a zero to tell Go it is an octal literal.
Also, remember that the 4th number doesn't exist like it does in chmod. With chmod, you could do 1700 to set the sticky bit. In Go, you would need to set the bit defined in the OS lib by doing something like: 0700 | os.ModeSticky

Community
- 1
- 1

Stephen Weinberg
- 51,320
- 14
- 134
- 113
-
-
1More info on the different permission bits can be found here http://stackoverflow.com/a/31151508/395461 – Shannon Matthews Jul 01 '15 at 02:13