zoukankan      html  css  js  c++  java
  • linux系统中chgrp命令

    linux系统中chgrp命令用户改变文件或者目录的所属组

    chgrp 为 change group的缩写

    用法: chgrp 【选项】 文件/目录

    1、创建测试文件

    [root@linuxprobe test]# ls
    [root@linuxprobe test]# whoami
    root
    [root@linuxprobe test]# touch a.txt b.txt
    [root@linuxprobe test]# su - liujiaxin01
    Last login: Tue Oct 20 21:29:13 CST 2020 on pts/0
    [liujiaxin01@linuxprobe ~]$ cd /home/test/
    [liujiaxin01@linuxprobe test]$ whoami
    liujiaxin01
    [liujiaxin01@linuxprobe test]$ touch c.txt d.txt
    [liujiaxin01@linuxprobe test]$ exit
    logout
    [root@linuxprobe test]# ll
    total 0
    -rw-r--r--. 1 root        root        0 Oct 20 21:42 a.txt
    -rw-r--r--. 1 root        root        0 Oct 20 21:42 b.txt
    -rw-rw-r--. 1 liujiaxin01 liujiaxin01 0 Oct 20 21:42 c.txt
    -rw-rw-r--. 1 liujiaxin01 liujiaxin01 0 Oct 20 21:42 d.txt

    2、直接用法

    [root@linuxprobe test]# ll
    total 0
    -rw-r--r--. 1 root        root        0 Oct 20 21:42 a.txt
    -rw-r--r--. 1 root        root        0 Oct 20 21:42 b.txt
    -rw-rw-r--. 1 liujiaxin01 liujiaxin01 0 Oct 20 21:42 c.txt
    -rw-rw-r--. 1 liujiaxin01 liujiaxin01 0 Oct 20 21:42 d.txt
    [root@linuxprobe test]# chgrp liujiaxin01 a.txt  ## 将a.txt的所属组改为刘家鑫01
    [root@linuxprobe test]# ll
    total 0
    -rw-r--r--. 1 root        liujiaxin01 0 Oct 20 21:42 a.txt
    -rw-r--r--. 1 root        root        0 Oct 20 21:42 b.txt
    -rw-rw-r--. 1 liujiaxin01 liujiaxin01 0 Oct 20 21:42 c.txt
    -rw-rw-r--. 1 liujiaxin01 liujiaxin01 0 Oct 20 21:42 d.txt
    [root@linuxprobe test]# chgrp root c.txt   ## 将c.txt的所属组改为root
    [root@linuxprobe test]# ll
    total 0
    -rw-r--r--. 1 root        liujiaxin01 0 Oct 20 21:42 a.txt
    -rw-r--r--. 1 root        root        0 Oct 20 21:42 b.txt
    -rw-rw-r--. 1 liujiaxin01 root        0 Oct 20 21:42 c.txt
    -rw-rw-r--. 1 liujiaxin01 liujiaxin01 0 Oct 20 21:42 d.txt

    3、可以直接使用组ID

    [root@linuxprobe test]# id root  ## 查看组ID
    uid=0(root) gid=0(root) groups=0(root)
    [root@linuxprobe test]# id liujiaxin01  ##查看组ID
    uid=1001(liujiaxin01) gid=1001(liujiaxin01) groups=1001(liujiaxin01)
    [root@linuxprobe test]# ll
    total 0
    -rw-r--r--. 1 root        liujiaxin01 0 Oct 20 21:42 a.txt
    -rw-r--r--. 1 root        root        0 Oct 20 21:42 b.txt
    -rw-rw-r--. 1 liujiaxin01 root        0 Oct 20 21:42 c.txt
    -rw-rw-r--. 1 liujiaxin01 liujiaxin01 0 Oct 20 21:42 d.txt
    [root@linuxprobe test]# chgrp 0 d.txt  ## 将d.txt的所属组改为root
    [root@linuxprobe test]# ll
    total 0
    -rw-r--r--. 1 root        liujiaxin01 0 Oct 20 21:42 a.txt
    -rw-r--r--. 1 root        root        0 Oct 20 21:42 b.txt
    -rw-rw-r--. 1 liujiaxin01 root        0 Oct 20 21:42 c.txt
    -rw-rw-r--. 1 liujiaxin01 root        0 Oct 20 21:42 d.txt
    [root@linuxprobe test]# chgrp 1001 b.txt  ## 将b.txt的组ID改为liujiaxin01
    [root@linuxprobe test]# ll
    total 0
    -rw-r--r--. 1 root        liujiaxin01 0 Oct 20 21:42 a.txt
    -rw-r--r--. 1 root        liujiaxin01 0 Oct 20 21:42 b.txt
    -rw-rw-r--. 1 liujiaxin01 root        0 Oct 20 21:42 c.txt
    -rw-rw-r--. 1 liujiaxin01 root        0 Oct 20 21:42 d.txt

    4、使用 -R 参数进行递归操作

    [root@linuxprobe test]# ls
    [root@linuxprobe test]# mkdir test01 test02
    [root@linuxprobe test]# touch test01/a.txt
    [root@linuxprobe test]# touch test02/b.txt
    [root@linuxprobe test]# ll
    total 0
    drwxr-xr-x. 2 root root 18 Oct 20 21:51 test01
    drwxr-xr-x. 2 root root 18 Oct 20 21:51 test02
    [root@linuxprobe test]# ll test01/a.txt
    -rw-r--r--. 1 root root 0 Oct 20 21:51 test01/a.txt
    [root@linuxprobe test]# ll test02/b.txt
    -rw-r--r--. 1 root root 0 Oct 20 21:51 test02/b.txt
    [root@linuxprobe test]# chgrp liujiaxin01 test01/
    [root@linuxprobe test]# chgrp -R liujiaxin01 test02/
    [root@linuxprobe test]# ll
    total 0
    drwxr-xr-x. 2 root liujiaxin01 18 Oct 20 21:51 test01
    drwxr-xr-x. 2 root liujiaxin01 18 Oct 20 21:51 test02
    [root@linuxprobe test]# ll test01/a.txt
    -rw-r--r--. 1 root root 0 Oct 20 21:51 test01/a.txt
    [root@linuxprobe test]# ll test02/b.txt   ## 加-R参数后,目录下的文件所属组同时改变
    -rw-r--r--. 1 root liujiaxin01 0 Oct 20 21:51 test02/b.txt

    5、--reference参数设置参考文件所属组修改文件或者目录所属组

    [root@linuxprobe test]# ll
    total 0
    -rw-r--r--. 1 root liujiaxin01 0 Oct 20 22:08 a.txt
    -rw-r--r--. 1 root root        0 Oct 20 22:08 b.txt
    [root@linuxprobe test]# chgrp --reference=b.txt a.txt  ## 将a.txt的所属组改为b.txt的所属组
    [root@linuxprobe test]# ll
    total 0
    -rw-r--r--. 1 root root 0 Oct 20 22:08 a.txt
    -rw-r--r--. 1 root root 0 Oct 20 22:08 b.txt
    [root@linuxprobe test]# chgrp liujiaxin01 b.txt
    [root@linuxprobe test]# ll
    total 0
    -rw-r--r--. 1 root root        0 Oct 20 22:08 a.txt
    -rw-r--r--. 1 root liujiaxin01 0 Oct 20 22:08 b.txt
    [root@linuxprobe test]# chgrp --reference=b.txt a.txt  ## 同上
    [root@linuxprobe test]# ll
    total 0
    -rw-r--r--. 1 root liujiaxin01 0 Oct 20 22:08 a.txt
    -rw-r--r--. 1 root liujiaxin01 0 Oct 20 22:08 b.txt
  • 相关阅读:
    Enterprise Library3.1 使用数据访问模块时,调用Microsoft.Practices.EnterpriseLibrary.Data报出源文件与当前应用程序不一致和创建dataconfiguration的配置节处理程序出错
    net精华:C#中对注册表的操作
    [翻译]使用Enterprise Library 3.0的日志程序块
    分布式应用程序概述
    调整Oracle数据库print_bill表字段BillMKID的顺序,并判断表print_bill是否存在及字段billMKID是否存在
    Win32下注册COM组件后对注册表产生的变动
    vc 字符串与指针
    SQL Server不允许进行远程连接的解决办法
    vc上字符串,CString ,string,char数组&char指针
    如何用Visual C#来创建、修改注册信息
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/13849446.html
Copyright © 2011-2022 走看看