首页·终端命令

stat

文件与目录

用法

stat [file]

把 inode 里的记录原样显示:大小、权限位、属主和三个时间;格式选项在 GNU 是 -c,在 BSD 是 -f,而 GNU 的 -f 完全是另一个意思。

常用选项

选项含义
-cGNU: choose the output format, as in -c %s
-fGNU: describe the filesystem. On BSD and macOS -f is the format string
-LFollow symlinks and report the target
-xBSD and macOS: verbose, labelled output
--printfGNU: like -c but adds no newline

示例

stat -c '%s %n' notes.md

Size and name (GNU).

stat -f '%z %N' notes.md

The same two values on macOS or BSD.

stat notes.md

Full record: size, mode, owner and the timestamps.

移动、删除和查找。有些命令不会再问一遍,所以顺手加 -i 是在救自己。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. stat 是做什么的?

把 inode 里的记录原样显示:大小、权限位、属主和三个时间;格式选项在 GNU 是 -c,在 BSD 是 -f,而 GNU 的 -f 完全是另一个意思。

Q. 怎么写?

stat [file] —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 5 个,完整列表在 man stat。这条命令属于文件与目录。

相关命令

man 手册: man stat