macos - OSX上“stat”输出的每个字段的含义是什么?
问题描述
$ stat Cargo.toml
16777220 9094681422 -rw-r--r-- 1 tonytonyjan staff 0 109 "Jan 19 10:05:13 2019" "Dec 31 17:52:29 2018" "Dec 31 17:52:29 2018" "Dec 14 16:32:26 2018" 4096 8 0 Cargo.toml
man stat
没有解释但提到输出是通过以下方式获得的lstat
:
显示的信息是通过使用给定参数调用 lstat(2) 并评估返回的结构来获得的。
之后man lstat
,它给出了一个看起来像我正在寻找的 C 结构:
The buf argument is a pointer to a stat structure as defined by <sys/stat.h> and into which information is placed concerning the file. When the macro
_DARWIN_FEATURE_64_BIT_INODE is not defined (see below for more information about this macro), the stat structure is defined as:
struct stat { /* when _DARWIN_FEATURE_64_BIT_INODE is NOT defined */
dev_t st_dev; /* device inode resides on */
ino_t st_ino; /* inode's number */
mode_t st_mode; /* inode protection mode */
nlink_t st_nlink; /* number of hard links to the file */
uid_t st_uid; /* user-id of owner */
gid_t st_gid; /* group-id of owner */
dev_t st_rdev; /* device type, for special file inode */
struct timespec st_atimespec; /* time of last access */
struct timespec st_mtimespec; /* time of last data modification */
struct timespec st_ctimespec; /* time of last file status change */
off_t st_size; /* file size, in bytes */
quad_t st_blocks; /* blocks allocated for file */
u_long st_blksize;/* optimal file sys I/O ops blocksize */
u_long st_flags; /* user defined flags for file */
u_long st_gen; /* file generation number */
};
不幸的是,我仍然无法将每个字段映射到 的输出stat
,例如:
$ stat Cargo.toml
16777220 9094681422 -rw-r--r-- 1 tonytonyjan staff 0 109 "Jan 19 10:05:13 2019" "Dec 31 17:52:29 2018" "Dec 31 17:52:29 2018" "Dec 14 16:32:26 2018" 4096 8 0 Cargo.toml
- 16777220 - 设备 inode 驻留在
- 9094681422 - 索引节点
- -rw-r--r-- - 保护模式
- 1 - 硬链接数
- tonytonyjan - 用户
- 员工组
- 0 -不确定。是设备类型吗?
- 109-尺寸
- “2019 年 1 月 19 日 10:05:13” - 最后访问
- “2018 年 12 月 31 日 17:52:29” - 最后修改
- “2018 年 12 月 31 日 17:52:29” - 最后文件状态更改
- “Dec 14 16:32:26 2018” -应该只有 3 个时间戳,这是什么?
- 4096 - 文件大小(以字节为单位)
- 8 - 为文件分配的块
- 0 -最佳文件系统 I/O 操作块大小?用户定义的标志?或文件代号?
- Cargo.toml - 文件名
我的问题:
- 第一个
0
代表st_rdev
吗? st_dev
和 和有什么不一样st_rdev
?- 秒
0
代表什么? - 很多时候我没有找到正确的
man
页面(也man stat
没有man lstat
)。有没有stat
详细解释每个字段的官方文档?我在哪里可以找到它?
解决方案
使用stat -s
. 它以相同的顺序打印字段,但带有标签(并省略文件名):
:; stat -s /etc/man.conf | fmt
st_dev=16777220 st_ino=641593 st_mode=0100644 st_nlink=1 st_uid=0
st_gid=0 st_rdev=0 st_size=4574 st_atime=1547885737 st_mtime=1500152545
st_ctime=1512806119 st_birthtime=1500152545 st_blksize=4194304
st_blocks=0 st_flags=32
您的第一个神秘领域是st_rdev
“设备类型,用于特殊文件 inode”。因为我们没有统计设备文件,所以这是零。
您的第二个神秘领域是st_birthtimespec
“文件创建时间(出生)”(参见stat(2)
手册页)。这是一个达尔文 64 位扩展。
您的 4096 不是以字节为单位的文件大小。它是st_blksize
“I/O 的最佳块大小”。在我的示例中,它是 4194304。也许您的文件位于 HFS+ 文件系统上。我的是在 APFS 文件系统上。
您的第三个神秘领域是st_flags
“用户定义的文件标志”。你的为零,所以没有设置标志。我的示例 ( /etc/man.conf
) 已UF_COMPRESSED
设置。
st_dev 和 st_rdev 有什么区别?
该st_dev
字段是指包含该文件的设备(硬盘驱动器/分区/其他)。st_rdev
设备文件的字段告诉内核文件本身代表什么设备。尝试stat
在 中的某些设备文件上运行/dev
,例如/dev/null
和/dev/rdisk0
以查看非零st_rdev
值。
很多时候我没有找到正确的手册页(man stat 和 man lstat 都没有)。有没有详细解释每个统计字段的官方文档?我在哪里可以找到它?
用于man 1 stat
了解命令行stat
程序的-s
标志,例如我使用的标志。然后使用man 2 stat
和您最喜欢的搜索引擎来了解这些字段的含义。
推荐阅读
- django - 使用相同的通用视图重用多个模型是否安全?
- html - 为什么 CSS text-align:left 不能与 Simplebar 一起使用?
- python - 使用 pymongo 将数组插入 mongodb
- c++ - 类公共部分的每一行的含义是什么?
- javascript - 加载与页面加载分开的图像
- node.js - 带有 node js 和 express / ejs 的站点并不总是加载图像
- ml.net - 如何对 ML.NET 预测进行单元测试?
- c++ - Leetcode #33 超过时间限制
- javascript - 在运行时替换字符串中的变量
- javascript - 在 node.js 中使用 websockets 发送消息