文件烫发八进制围棋位Linux上

问题描述 投票:2回答:1

我试图让八进制表示文件权限位。下面的代码打印出它作为字符串。有没有在八进制转换为打印或诠释的API?

import "os"
import "fmt"

func main() {
    m, _ := os.Stat("test.go")
    perm := m.Mode().Perm()
    fmt.Println(perm)
}   
$:~/gocode/ws/gocode$ go run perm.go 
-rw-rw-r--
@:~/gocode/ws/gocode$ 
go file-permissions
1个回答
4
投票

例如,

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
© www.soinside.com 2019 - 2024. All rights reserved.