id
權限與擁有者
用法
id [user]印出行程執行時的使用者和群組 id;id -u 回傳 0 就是 root,這也是指令檔判斷管理員權限的標準做法。
常用選項
| 選項 | 含義 |
|---|---|
| -u | The numeric user id only; 0 means root |
| -g | The primary group id |
| -G | Every group id the user is in |
| -n | Names instead of numbers, with -u, -g or -G |
| -r | The real id rather than the effective one |
範例
idYour uid, gid and every group at once.
id -uJust the number, which scripts test against 0.
id -nG deployThe group names of another user.
數字模式和符號模式說的是同一件事:755 和 u=rwx,go=rx 是同一個權限。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. id 是做什麼的?
印出行程執行時的使用者和群組 id;id -u 回傳 0 就是 root,這也是指令檔判斷管理員權限的標準做法。
Q. 怎麼寫?
id [user] —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 5 個,完整列表在 man id。這條命令屬於權限與擁有者。
相關命令
man 手冊: man id