2015-04-27 11:50
浏览 418


I am creating a folder in go using os.Mkdir(). While it does get created, it does not possess the permissions I expected it to.

Here is the code I used to create the directory:

package main

import (

func main() {
    err := os.Mkdir("/var/run/testdir", 0777)
    if err != nil {
        fmt.Println("could not create dir: %s", err.Error())
        err = nil

As I have given "0777" as parameter, I am excpecting the created dir to have full permissions for everybody. It however has:

drwxr-xr-x  2 root       root         40 Apr 27 11:43 testdir/

What am I getting wrong here?

图片转代码服务由CSDN问答提供 功能建议

我正在使用os.Mkdir()创建一个文件夹。 虽然确实创建了它,但它不具备我期望的权限。


   package main 
“ fmt” 
“ os” 
func main(){
 err:= os.Mkdir(“ / var / run / testdir”,0777  )
 if err!= nil {
 err = nil 

由于我给定了“ 0777”作为参数,我期望创建的目录对所有人具有完全权限。 但是它具有:

  drwxr-xr-x 2根root 40 Apr 27 11:43 testdir / 


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutizhou5312 2015-04-27 12:07

    The actual permission that the created folder will get is the result of the permission you specify (0777) and the active umask of your process (the running Go program).

    This is most likely why the created folder lacks write permission for group and other access.

    You can read more about umask on Wikipedia.

    解决 无用
    打赏 举报

相关推荐 更多相似问题