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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With