命令名称

chown

命令描述

变更文件或者目录所属用户

语法

chown 【参数】【用户:组】 【文件或者目录】

参数

-R 递归 -V显示

案例一:更换文件的所有者和所有组

[root@localhost /]# chown AAA:AAA 1.txt 
[root@localhost /]# ls
1.txt  bbbbb  boot  etc   lib	 media	opt   root  sbin  sys  usr
AAA    bin    dev   home  lib64  mnt	proc  run   srv   tmp  var
[root@localhost /]# ls -l
总用量 40
-rwxrw-rw-.   1 AAA  AAA  7064 12月 18 16:49 1.txt

案例二:更换指定目录下的所有文件目录和组

[root@localhost /]# chown -Rv AAA:AAA ABC
changed ownership of "ABC/A/B/C/D" from root:root to AAA:AAA
changed ownership of "ABC/A/B/C" from root:root to AAA:AAA
changed ownership of "ABC/A/B" from root:root to AAA:AAA
changed ownership of "ABC/A" from root:root to AAA:AAA
changed ownership of "ABC" from root:root to AAA:AAA
[root@localhost /]# 

案例三:更换所有组

[root@localhost /]# chown -R :root ABC
[root@localhost /]# ls -l
总用量 40
-rwxrw-rw-.   1 AAA  AAA  7064 12月 18 16:49 1.txt
drwxrwxrwx.   3 root root   16 12月 18 18:40 AAA
drwxr-xr-x.   3 AAA  root   14 12月 18 19:10 ABC

案例四:更换所有者

[root@localhost /]# chown AAA: AAA
[root@localhost /]# ls -l
总用量 40
-rwxrw-rw-.   1 AAA  AAA  7064 12月 18 16:49 1.txt
drwxrwxrwx.   3 AAA  AAA    16 12月 18 18:40 AAA

PS:更换组权限还有一个命令是chgrp ,但是这个命令更换不了用户权限所以用的不多。