chown #修改属主属组
-R #递归设置
chgrp #只能修改属组
?
只有root权限才可以任意修改属主属组
普通用户不能使用这个命令
?
[root@lxy ~]# cd /opt/
[root@lxy /opt]#
[root@lxy /opt]# ll
total 12
-rw-rw--w-. 1 yuwei yuwei 10 Dec 17 18:36 123
-rw-r---w-. 1 test test 9 Dec 17 18:41 passwd
drwxr-x-wx. 2 root root 70 Dec 17 19:04 test
-rw-r---w-. 1 root root 9 Dec 17 18:33 test.txt
[root@lxy /opt]# id test
uid=1000(test) gid=1000(test) groups=1000(test)
[root@lxy /opt]# chown test.test 123
[root@lxy /opt]# ll
total 12
-rw-rw--w-. 1 test test 10 Dec 17 18:36 123
-rw-r---w-. 1 test test 9 Dec 17 18:41 passwd
drwxr-x-wx. 2 root root 70 Dec 17 19:04 test
-rw-r---w-. 1 root root 9 Dec 17 18:33 test.txt
[root@lxy /opt]# chown yuwei passwd
[root@lxy /opt]# ll
total 12
-rw-rw--w-. 1 test test 10 Dec 17 18:36 123
-rw-r---w-. 1 yuwei test 9 Dec 17 18:41 passwd
drwxr-x-wx. 2 root root 70 Dec 17 19:04 test
-rw-r---w-. 1 root root 9 Dec 17 18:33 test.txt
[root@lxy /opt]# chown .yuwei 123
[root@lxy /opt]# ll
total 12
-rw-rw--w-. 1 test yuwei 10 Dec 17 18:36 123
-rw-r---w-. 1 yuwei test 9 Dec 17 18:41 passwd
drwxr-x-wx. 2 root root 70 Dec 17 19:04 test
-rw-r---w-. 1 root root 9 Dec 17 18:33 test.txt
[root@lxy /opt]# chown root:root 123
[root@lxy /opt]# ll
total 12
-rw-rw--w-. 1 root root 10 Dec 17 18:36 123
-rw-r---w-. 1 yuwei test 9 Dec 17 18:41 passwd
drwxr-x-wx. 2 root root 70 Dec 17 19:04 test
-rw-r---w-. 1 root root 9 Dec 17 18:33 test.txt
[root@lxy /opt]# chgrp test 123
[root@lxy /opt]# ll
total 12
-rw-rw--w-. 1 root test 10 Dec 17 18:36 123
-rw-r---w-. 1 yuwei test 9 Dec 17 18:41 passwd
drwxr-x-wx. 2 root root 70 Dec 17 19:04 test
-rw-r---w-. 1 root root 9 Dec 17 18:33 test.txt
?
[root@lxy /opt]# chown -R test.test test #递归设置
[root@lxy /opt]# ll
total 12
-rw-rw--w-. 1 root test 10 Dec 17 18:36 123
-rw-r---w-. 1 yuwei test 9 Dec 17 18:41 passwd
drwxr-x-wx. 2 test test 70 Dec 17 19:04 test
-rw-r---w-. 1 root root 9 Dec 17 18:33 test.txt
[root@lxy /opt]