00. 目录
文章目录
- 00. 目录
- 01. 命令概述
- 02. 命令格式
- 03. 常用选项
- 04. 参考示例
- 05. 总结
- 06. 附录
01. 命令概述
chgrp是英语单词“change group”的缩写,命令的作用和其中文释义一样,为用于变更文件或目录的所属群组。
chgrp命令用来改变文件或目录所属的用户组。该命令用来改变指定文件所属的用户组。其中,组名可以是用户组的id,也可以是用户组的组名。文件名可以 是由空格分开的要改变属组的文件列表,也可以是由通配符描述的文件集合。如果用户不是该文件的文件主或超级用户(root),则不能改变该文件的组。
在UNIX系统家族里,文件或目录权限的掌控以拥有者及所属群组来管理。您可以使用chgrp指令去变更文件与目录的所属群组,设置方式采用群组名称或群组识别码皆可。
02. 命令格式
用法:chgrp [选项]... 用户组 文件...
或:chgrp [选项]... --reference=参考文件 文件...
03. 常用选项
-c或——changes:效果类似“-v”参数,但仅回报更改的部分;
-f或--quiet或——silent:不显示错误信息;
-h或--no-dereference:只对符号连接的文件作修改,而不是该其他任何相关文件;
-R或——recursive:递归处理,将指令目录下的所有文件及子目录一并处理;
-v或——verbose:显示指令执行过程;
--reference=<参考文件或目录>:把指定文件或目录的所属群组全部设成和参考文件或目录的所属群组相同;
04. 参考示例
4.1 修改文件所属组
[root@itcast test]# chgrp deng file
[root@itcast test]# ls -l file
-rwxr-x--x 1 itcast deng 0 8月 6 20:06 file
[root@itcast test]#
4.2 修改文件所属组,同时显示执行过程
[root@itcast test]# chgrp -v root file
changed group of "file" from deng to root
[root@itcast test]#
4.3 根据指定文件改变文件的群组属性
[root@itcast test]# chgrp --reference=/etc/passwd file
[root@itcast test]# ls -l file
-rwxr-x--x 1 itcast root 0 8月 6 20:06 file
[root@itcast test]#
4.4 递归修改指定目录下所有的文件和目录所属组
[root@itcast test]# chgrp -R deng test/
4.5 通过组ID修改文件所属组
[root@itcast test]# chgrp 1003 file
[root@itcast test]# ls -l file
-rwxr-x--x 1 itcast itcast 0 8月 6 20:06 file
[root@itcast test]#
05. 总结
06. 附录
参考:【Linux】一步一步学Linux系列教程汇总