您的位置首页生活百科

如何使用chown?(图文教程)

如何使用chown?(图文教程)

的有关信息介绍如下:

如何使用chown?(图文教程)

在使用linux系统时,常用的指令还是常用的,也是必须会用的。chown主要是修改文件的所有者,一个文件可以归某个用户所有,同时也归某个组所有,但是这里的某个用户和某组的名称可以一样也可以不一样的。本教程以图文方式详细介绍命令chown的使用。

以test为例,目前test归root用户拥有,也归root组拥有

[root@localhost home]# ls -al

total 36

drwxr-xr-x 6 root root 4096 Jan 28 12:20 .

drwxr-xr-x 21 root root 4096 Jan 27 20:20 ..

drwxr-xr-x 5 redhat3 root 4096 Jan 28 11:57 eda

drwx------ 2 root root 16384 Jan 25 20:40 lost+found

drwx------ 13 redhat3 redhat3 4096 Jan 28 12:03 redhat3

drwxr-xr-x 2 root root 4096 Jan 28 12:20 test

现在若这样执行命令的话,则归redhat3用户拥有,但是还是归root组,意思是只修改了用户,没有修改组

[root@localhost home]# ls -al

total 36

drwxr-xr-x 6 root root 4096 Jan 28 12:20 .

drwxr-xr-x 21 root root 4096 Jan 27 20:20 ..

drwxr-xr-x 5 redhat3 root 4096 Jan 28 11:57 eda

drwx------ 2 root root 16384 Jan 25 20:40 lost+found

drwx------ 13 redhat3 redhat3 4096 Jan 28 12:03 redhat3

drwxr-xr-x 2 redhat3 root 4096 Jan 28 12:20 test

现在若这样执行命令的话,则归redhat3用户拥有,组也改为redhat3组,意思是修改了用户,也修改组

[root@localhost home]# chown redhat3:redhat3 /home/test/

[root@localhost home]# ls -al

现在若这样执行命令的话,则归redhat3用户拥有,组也改为root组,意思是修改了用户,也修改组

用户修改 组也修改

[root@localhost home]# chown redhat3:root /home/test/

[root@localhost home]# ls -al

total 36

drwxr-xr-x 6 root root 4096 Jan 28 12:20 .

drwxr-xr-x 21 root root 4096 Jan 27 20:20 ..

drwxr-xr-x 5 redhat3 redhat3 4096 Jan 28 11:57 eda

drwx------ 2 root root 16384 Jan 25 20:40 lost+found

drwx------ 13 redhat3 redhat3 4096 Jan 28 12:03 redhat3

drwxr-xr-x 2 redhat3 root 4096 Jan 28 12:20 test

现在若这样执行命令的话,则归redhat3用户拥有,组也改为redhat3组,意思是修改了用户,也修改修改组不过这种方法是redhat3:后面省略了组名。用户修改,组也修改,不过该组就是该用户登录时所属的组

[root@localhost home]# chown redhat3: /home/test/

[root@localhost home]# ls -al

total 36

drwxr-xr-x 6 root root 4096 Jan 28 12:20 .

drwxr-xr-x 21 root root 4096 Jan 27 20:20 ..

drwxr-xr-x 5 redhat3 redhat3 4096 Jan 28 11:57 eda

drwx------ 2 root root 16384 Jan 25 20:40 lost+found

drwx------ 13 redhat3 redhat3 4096 Jan 28 12:03 redhat3

drwxr-xr-x 2 redhat3 redhat3 4096 Jan 28 12:20 test

现在若这样执行命令的话,则归redhat3用户没有变,组也改为root组,意思是只修改了组

[root@localhost home]# chown :root /home/test/

[root@localhost home]# ls -al

total 36

drwxr-xr-x 6 root root 4096 Jan 28 12:20 .

drwxr-xr-x 21 root root 4096 Jan 27 20:20 ..

drwxr-xr-x 5 redhat3 redhat3 4096 Jan 28 11:57 eda

drwx------ 2 root root 16384 Jan 25 20:40 lost+found

drwx------ 13 redhat3 redhat3 4096 Jan 28 12:03 redhat3

drwxr-xr-x 2 redhat3 root 4096 Jan 28 12:20 test

[root@localhost home]#

总结:chown 用户名:组 名 文件 若同时修改用户名和组名时,需要把两者都写上,若只修改用户名的话,则组名及其用户名后面的冒号就不要用;若只修改组名,而用户名不修改的话,则是:组名;若只修改的用户名,组名就是所登录时的组名的话,就是用户名: