Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux in Go上的八进制文件perm位_Go_File Permissions - Fatal编程技术网

Linux in Go上的八进制文件perm位

Linux in Go上的八进制文件perm位,go,file-permissions,Go,File Permissions,我正在尝试获取八进制表示的文件权限位。 下面的代码将其打印为字符串。有八进制打印的API吗 还是int 比如说, package main import ( "fmt" "os" "strconv" ) func main() { fi, err := os.Stat("test.go") if err != nil { fmt.Fprintln(os.Stderr, err) return } perm

我正在尝试获取八进制表示的文件权限位。 下面的代码将其打印为字符串。有八进制打印的API吗 还是int

比如说,

package main

import (
    "fmt"
    "os"
    "strconv"
)

func main() {
    fi, err := os.Stat("test.go")
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
        return
    }
    perm := fi.Mode().Perm()
    fmt.Println(perm)
    fmt.Printf("%o\n", perm)
    fmt.Printf("%#o\n", perm)
    fmt.Println(strconv.FormatUint(uint64(perm), 8))
    fmt.Println("0" + strconv.FormatUint(uint64(perm), 8))
}
输出:

-rw-rw-r--
664
0664
664
0664
package main

import (
    "fmt"
    "os"
    "strconv"
)

func main() {
    fi, err := os.Stat("test.go")
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
        return
    }
    perm := fi.Mode().Perm()
    fmt.Println(perm)
    fmt.Printf("%o\n", perm)
    fmt.Printf("%#o\n", perm)
    fmt.Println(strconv.FormatUint(uint64(perm), 8))
    fmt.Println("0" + strconv.FormatUint(uint64(perm), 8))
}
-rw-rw-r--
664
0664
664
0664