linux命令--chgrp

功能说明

chgrp命令用来改变文件或目录所属的用户组。其中,组名可以是用户组的id,也可以是用户组的组名。文件名可以 是由空格分开的要改变属组的文件列表,也可以是由通配符描述的文件集合。如果用户不是该文件的文件主或超级用户(root),则不能改变该文件的组。

来自: http://man.linuxde.net/chgrp

常用选项

语法
chgrp(选项)(参数)

选项

必要选项:

-c 当发生改变时输出调试信息
-f 不显示错误信息
-R 处理指定目录以及其子目录下的所有文件
-v 运行时显示详细的处理信息
–dereference 作用于符号链接的指向,而不是符号链接本身
–no-dereference 作用于符号链接本身

选择选项:

–reference=<文件或者目录>
–help 显示帮助信息
–version 显示版本信息

参数
组:指定新工作名称;
文件:指定要改变所属组的文件列表。多个文件或者目录之间使用空格隔开。

使用实例

1.改变文件的群组属性

scarlett@scarlett-X550VXK:~/file$ sudo chgrp root 1.txt
[sudo] scarlett 的密码: 
scarlett@scarlett-X550VXK:~/file$ ls -l
总用量 48
-r--rwx--x 2 root     root 2099 1010 16:17 10.txt
-rw-rw-r-- 1 root     root 1121 1010 16:17 15.txt
-rw-rw-r-- 1 root     root 1419 1010 16:17 16.txt
-rw-rw-r-- 2 scarlett root    0 1010 20:35 1.txt
-rw-rw-r-- 1 root     root  419 1010 16:17 20.txt
-rw-rw-r-- 1 root     root 1124 1010 16:17 21.txt
-rw-rw-r-- 1 root     root  540 1010 16:17 22.txt
-rw-rw-r-- 1 root     root 1168 1010 16:17 23.txt
-rw-rw-r-- 1 root     root 9113 1010 16:17 24.txt
-rw-rw-r-- 1 root     root   42 1010 16:17 2.txt
-rw-rw-r-- 1 root     root 1854 1010 16:17 5.txt

2.根据指定文件改变指定目录下所有文件的所属群组

scarlett@scarlett-X550VXK:~/file$ ls -l
总用量 48
-r--rwx--x 2 root     root     2099 1010 16:17 10.txt
-rw-rw-r-- 1 root     root     1121 1010 16:17 15.txt
-rw-rw-r-- 1 root     root     1419 1010 16:17 16.txt
-rw-rw-r-- 2 scarlett scarlett    0 1010 20:35 1.txt
-rw-rw-r-- 1 root     root      419 1010 16:17 20.txt
-rw-rw-r-- 1 root     root     1124 1010 16:17 21.txt
-rw-rw-r-- 1 root     root      540 1010 16:17 22.txt
-rw-rw-r-- 1 root     root     1168 1010 16:17 23.txt
-rw-rw-r-- 1 root     root     9113 1010 16:17 24.txt
-rw-rw-r-- 1 root     root       42 1010 16:17 2.txt
-rw-rw-r-- 1 root     root     1854 1010 16:17 5.txt
scarlett@scarlett-X550VXK:~/file$ sudo chgrp --reference=1.txt -R ./
scarlett@scarlett-X550VXK:~/file$ ls -l
总用量 48
-r--rwx--x 2 root     scarlett 2099 1010 16:17 10.txt
-rw-rw-r-- 1 root     scarlett 1121 1010 16:17 15.txt
-rw-rw-r-- 1 root     scarlett 1419 1010 16:17 16.txt
-rw-rw-r-- 2 scarlett scarlett    0 1010 20:35 1.txt
-rw-rw-r-- 1 root     scarlett  419 1010 16:17 20.txt
-rw-rw-r-- 1 root     scarlett 1124 1010 16:17 21.txt
-rw-rw-r-- 1 root     scarlett  540 1010 16:17 22.txt
-rw-rw-r-- 1 root     scarlett 1168 1010 16:17 23.txt
-rw-rw-r-- 1 root     scarlett 9113 1010 16:17 24.txt
-rw-rw-r-- 1 root     scarlett   42 1010 16:17 2.txt
-rw-rw-r-- 1 root     scarlett 1854 1010 16:17 5.txt

3.通过群组识别码改变文件属组属性。

通过群组识别码改变文件群组属性,100为users群组的识别码,具体群组和群组识别码可以去/etc/group文件中查看

scarlett@scarlett-X550VXK:~/file$ ls -l
总用量 48
-r--rwx--x 2 root     scarlett 2099 1010 16:17 10.txt
-rw-rw-r-- 1 root     scarlett 1121 1010 16:17 15.txt
-rw-rw-r-- 1 root     scarlett 1419 1010 16:17 16.txt
-rw-rw-r-- 2 scarlett scarlett    0 1010 20:35 1.txt
-rw-rw-r-- 1 root     scarlett  419 1010 16:17 20.txt
-rw-rw-r-- 1 root     scarlett 1124 1010 16:17 21.txt
-rw-rw-r-- 1 root     scarlett  540 1010 16:17 22.txt
-rw-rw-r-- 1 root     scarlett 1168 1010 16:17 23.txt
-rw-rw-r-- 1 root     scarlett 9113 1010 16:17 24.txt
-rw-rw-r-- 1 root     scarlett   42 1010 16:17 2.txt
-rw-rw-r-- 1 root     scarlett 1854 1010 16:17 5.txt
scarlett@scarlett-X550VXK:~/file$ sudo chgrp 100 -R ./
scarlett@scarlett-X550VXK:~/file$ ls -l
总用量 48
-r--rwx--x 2 root     users 2099 1010 16:17 10.txt
-rw-rw-r-- 1 root     users 1121 1010 16:17 15.txt
-rw-rw-r-- 1 root     users 1419 1010 16:17 16.txt
-rw-rw-r-- 2 scarlett users    0 1010 20:35 1.txt
-rw-rw-r-- 1 root     users  419 1010 16:17 20.txt
-rw-rw-r-- 1 root     users 1124 1010 16:17 21.txt
-rw-rw-r-- 1 root     users  540 1010 16:17 22.txt
-rw-rw-r-- 1 root     users 1168 1010 16:17 23.txt
-rw-rw-r-- 1 root     users 9113 1010 16:17 24.txt
-rw-rw-r-- 1 root     users   42 1010 16:17 2.txt
-rw-rw-r-- 1 root     users 1854 1010 16:17 5.txt
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值