多语言展示
当前在线:1924今日阅读:103今日分享:49

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

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

PC

2

linux

方法/步骤
1

以test为例,目前test归root用户拥有,也归root组拥有[root@localhost home]# ls -altotal 36drwxr-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 edadrwx------    2 root     root        16384 Jan 25 20:40 lost+founddrwx------   13 redhat3  redhat3      4096 Jan 28 12:03 redhat3drwxr-xr-x    2 root     root         4096 Jan 28 12:20 test

2

现在若这样执行命令的话,则归redhat3用户拥有,但是还是归root组,意思是只修改了用户,没有修改组[root@localhost home]# ls -altotal 36drwxr-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 edadrwx------    2 root     root        16384 Jan 25 20:40 lost+founddrwx------   13 redhat3  redhat3      4096 Jan 28 12:03 redhat3drwxr-xr-x    2 redhat3  root         4096 Jan 28 12:20 test

3

现在若这样执行命令的话,则归redhat3用户拥有,组也改为redhat3组,意思是修改了用户,也修改组 [root@localhost home]# chown redhat3:redhat3 /home/test/[root@localhost home]# ls -al

4

现在若这样执行命令的话,则归redhat3用户拥有,组也改为root组,意思是修改了用户,也修改组 用户修改 组也修改[root@localhost home]# chown redhat3:root /home/test/[root@localhost home]# ls -altotal 36drwxr-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 edadrwx------    2 root     root        16384 Jan 25 20:40 lost+founddrwx------   13 redhat3  redhat3      4096 Jan 28 12:03 redhat3drwxr-xr-x    2 redhat3  root         4096 Jan 28 12:20 test

5

现在若这样执行命令的话,则归redhat3用户拥有,组也改为redhat3组,意思是修改了用户,也修改修改组不过这种方法是redhat3:后面省略了组名。用户修改,组也修改,不过该组就是该用户登录时所属的组[root@localhost home]# chown redhat3: /home/test/[root@localhost home]# ls -altotal 36drwxr-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 edadrwx------    2 root     root        16384 Jan 25 20:40 lost+founddrwx------   13 redhat3  redhat3      4096 Jan 28 12:03 redhat3drwxr-xr-x    2 redhat3  redhat3      4096 Jan 28 12:20 test

6

现在若这样执行命令的话,则归redhat3用户没有变,组也改为root组,意思是只修改了组 [root@localhost home]# chown :root /home/test/[root@localhost home]# ls -altotal 36drwxr-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 edadrwx------    2 root     root        16384 Jan 25 20:40 lost+founddrwx------   13 redhat3  redhat3      4096 Jan 28 12:03 redhat3drwxr-xr-x    2 redhat3  root         4096 Jan 28 12:20 test[root@localhost home]#

7

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

注意事项
1

上述中用到冒号的地方也可以换成点。

2

根据具体情况修改具体的项。

推荐信息