首页·终端命令

chgrp

权限与归属

用法

chgrp [group] [path]

只改文件的属组,chown 用 :group 也能做到;不是 root 的话,只能指定自己所属的组。

常用选项

选项含义
-RApply to a whole tree
-hChange the symlink itself
-vReport each change
--referenceGNU: take the group from another file

示例

chgrp -R developers /srv/project

Whole tree over to the developers group.

chgrp staff notes.txt

Works only if you belong to staff.

数字模式和符号模式说的是同一件事:755 和 u=rwx,go=rx 是同一个权限。

怎么看

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

常见问题

Q. chgrp 是做什么的?

只改文件的属组,chown 用 :group 也能做到;不是 root 的话,只能指定自己所属的组。

Q. 怎么写?

chgrp [group] [path] —— 方括号表示可以省略的部分。

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

这里列了 4 个,完整列表在 man chgrp。这条命令属于权限与归属。

相关命令

man 手册: man chgrp