2015-11-08 11:17
采纳率: 100%
浏览 173

来自os.Stat / Lstat的目录大小

Let's say I do an os.Stat() on a directory:

func main() {
    fi, _ := os.Stat("/tmp")

// 548
// Program exited.

What exactly is the [FileInfo].Size() value meant to represent? It's not the file size, so I'm guessing something like number of files? Inodes? I couldn't find a clear answer anywhere, so maybe someone can enlighten me?

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

比方说,我在目录上执行了 os.Stat()

  func main(){
 fi,_:= os.Stat(“ / tmp”)
 /  / 548 

[FileInfo] .Size()值的确切含义是什么 代表? 这不是文件大小,所以我猜大概是文件数之类的吗? 信息节点? 我在任何地方都找不到清晰的答案,所以也许有人可以启发我?

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

1条回答 默认 最新

  • dongtui0650 2015-11-08 11:48

    FileInfo mentions

    // length in bytes for regular files; system-dependent for others

    So it really depends on the execution environment.
    See for instance "Where does ext4 store directory sizes?"

    In that example, a directory stat size returns 4096 bytes.
    That's the actual size of the directory itself, not what it contains.

    The stat command provides no facility for querying anything other then the size of a filesystem object (directory or file).

    stat simply doesn't have a way to return multiple sizes—so it can only return the size of the directory itself, not of its contents.
    And also "directory size including contents" becomes less clear when you have hardlinked files.

    解决 无用
    打赏 举报

相关推荐 更多相似问题