chown 修改属主、属组
1、修改一个文件的所属主、所属组
[root@wy ~]# ls -l 111.txt
-rw-r--r-- 1 root root 0 9月 20 20:48 111.txt
#先创建一个用户
[root@wy ~]# useradd wyy
#修改文件的所属主
[root@wy ~]# chown wyy 111.txt
[root@wy ~]# ls -l 111.txt
-rw-r--r-- 1 wyy root 0 9月 20 20:48 111.txt
#创建用户组
[root@wy ~]# groupadd users1
#修改文件的所属组
[root@wy ~]# chown :users1 111.txt
[root@wy ~]# ls -l 111.txt
-rw-r--r-- 1 wyy users1 0 9月 20 20:48 111.txt
2、把文件原来的所属主、所属组修改回来
[root@wy ~]# chown root:root 111.txt
[root@wy ~]# ls -l 111.txt
-rw-r--r-- 1 root root 0 9月 20 20:48 111.txt
说明:有时候有的人中间冒号写点,即root.root
3、修改目录的下的所有子目录的所属主、所属组(同chmod继承权限一个道理)
[root@wy ~]# ls -ld 123
drwxr-xr-x 3 root root 4096 9月 20 21:01 123
[root@wy ~]# chown -R wyy:users1 123
[root@wy ~]# ls -l 123
总用量 4
-rw-r--r-- 1 wyy users1 0 9月 20 20:48 111.txt
drwxr-xr-x 2 wyy users1 4096 9月 20 21:01 222
4、只修改所属组也可以这样
chgrp users1 1.txt
本文出自 “linux” 博客,转载请与作者联系!
原文:http://warm51fun.blog.51cto.com/3884274/1891538