stat
檔案與目錄
用法
stat [file]把 inode 裡的記錄原樣顯示:大小、權限位、擁有者和三個時間;格式選項在 GNU 是 -c,在 BSD 是 -f,而 GNU 的 -f 完全是另一個意思。
常用選項
| 選項 | 含義 |
|---|---|
| -c | GNU: choose the output format, as in -c %s |
| -f | GNU: describe the filesystem. On BSD and macOS -f is the format string |
| -L | Follow symlinks and report the target |
| -x | BSD and macOS: verbose, labelled output |
| --printf | GNU: like -c but adds no newline |
範例
stat -c '%s %n' notes.mdSize and name (GNU).
stat -f '%z %N' notes.mdThe same two values on macOS or BSD.
stat notes.mdFull 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