chown:更改文件或目录的用户和用户组

xiaohai 2021-05-05 16:59:16 1597人围观 标签: Linux 
简介chown命令用于改变文件或目录的用户或用户组

说明

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

格式

  chown [option] [用户].[用户组] [file]

常用格式:

  • chown 用户 文件或目录
  • chown :用户组 文件或目录
  • chown 用户:用户组 文件或目录
    注意:”:”可以使用”.”代替

常用参数

  • -R:递归更改目录的用户和用户组
[root@localhost dir1]# ll
total 0
----------. 1 root root 0 May  7 22:34 test1.txt
----------. 1 root root 0 May  7 22:34 test2.txt
----------. 1 root root 0 May  7 22:34 test3.txt
[root@localhost dir1]# chown skip test1.txt #更改文件的用户
[root@localhost dir1]# ll
total 0
----------. 1 skip root 0 May  7 22:34 test1.txt
----------. 1 root root 0 May  7 22:34 test2.txt
----------. 1 root root 0 May  7 22:34 test3.txt
[root@localhost dir1]# chown .skip test2.txt  #更改文件的用户组
[root@localhost dir1]# ll
total 0
----------. 1 skip root 0 May  7 22:34 test1.txt
----------. 1 root skip 0 May  7 22:34 test2.txt
----------. 1 root root 0 May  7 22:34 test3.txt
[root@localhost dir1]# chown skip.skip test2.txt #更改文件的用户和用户组
[root@localhost dir1]# ll
total 0
----------. 1 skip root 0 May  7 22:34 test1.txt
----------. 1 skip skip 0 May  7 22:34 test2.txt
----------. 1 root root 0 May  7 22:34 test3.txt

[root@localhost dir1]# chown -R root.root ./* #递归更改文件的用户和用户组
[root@localhost dir1]# ll
total 0
----------. 1 root root 0 May  7 22:34 test1.txt
----------. 1 root root 0 May  7 22:34 test2.txt
----------. 1 root root 0 May  7 22:34 test3.txt