根據(jù)FileInfo的手冊頁,stat()在 Go 中 ing 文件時可以使用以下信息:type FileInfo interface { Name() string // base name of the file Size() int64 // length in bytes for regular files; system-dependent for others Mode() FileMode // file mode bits ModTime() time.Time // modification time IsDir() bool // abbreviation for Mode().IsDir() Sys() interface{} // underlying data source (can return nil)}如何在 Go 中檢索特定文件的硬鏈接數(shù)?UNIX ( <sys/stat.h>) 將st_nlink(“硬鏈接的引用計數(shù)” )定義為stat()系統(tǒng)調用的返回值。
1 回答

慕絲7291255
TA貢獻1859條經(jīng)驗 獲得超6個贊
例如,在 Linux 上,
package main
import (
"fmt"
"os"
"syscall"
)
func main() {
fi, err := os.Stat("filename")
if err != nil {
fmt.Println(err)
return
}
nlink := uint64(0)
if sys := fi.Sys(); sys != nil {
if stat, ok := sys.(*syscall.Stat_t); ok {
nlink = uint64(stat.Nlink)
}
}
fmt.Println(nlink)
}
輸出:
1
- 1 回答
- 0 關注
- 215 瀏覽
添加回答
舉報
0/150
提交
取消