说明

chown 命令用于改变文件或目录的所属用户或组。


一、语法格式

        chown   [option]   [owner][:[group]]   [文件或目录名称]

        常用格式有:

        1、chown 用户        文件或目录

        2、chown :组        文件或目录

        3、chown 用户:组        文件或目录

        备注:要授权的用户名和组,必须是系统中已经存在的。

        参数:-R 递归的进行修改目录的用户名和用户组。

二、案例

        1、修改文件所属用户

[root@cenos79 test]# chown test sort.txt  ## 修改 sort.txt 所属用户
[root@cenos79 test]# ll sort.txt 
-rw-r--r-- 1 test root 84 Jun 26 11:35 sort.txt
[root@cenos79 test]# ^C
[root@cenos79 test]# 

        2、修改文件用户组

[root@cenos79 test]# chown :test sort.txt 
[root@cenos79 test]# ll sort.txt 
-rw-r--r-- 1 test test 84 Jun 26 11:35 sort.txt
[root@cenos79 test]# 

        3、同时修改用户名和组

[root@cenos79 test]# chown root:root sort.txt 
[root@cenos79 test]# ll sort.txt 
-rw-r--r-- 1 root root 84 Jun 26 11:35 sort.txt
[root@cenos79 test]# 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐