0
点赞
收藏
分享

微信扫一扫

linux基本操作命令(三)


chown 是修改文件和目录的所有者和所属组的命令,其基本信息如下。


  • 命令名称:chown。
  • 文原意:change file owner and group。
  • 所在路径:/bin/chown。
  • 执行权限:所有用户。
  • 功能描述:修改文件和目录的所有者和所属组。
  • -R: 递归设置权限,也就是给子目录中的所有文件设置权

【例 3】普通用户修改权限。

笔者在讲权限作用的时候强调过,并不是只有 root 用户才可以修改文件的权限,而是超级用户可以修改任何文件的权限,普通用户只能修改自己文件的权限。也就是说,只有普通用户是这个文件的所有者,才可以修改文件的权限。我们试试:

[root@localhost ~]# cd /home/user/
#进入user用户的家目录
[root@localhost user]# touch test
#由root用户新建文件test
[root@localhost user]# ll test
-rw-r--r--1 root root 0 6月 16 05:37 test
#文件所有者和所属组都是root用户
[root@localhost user]# su- user
#切换为user用户
[user@localhost ~]$ chmod 755 test
chmod:更改"test"的权限:不允许的操作 #user用户不能修改test文件的权限
[user@localhost ~]$ exit
#退回到root身份
[root@localhost user]# chown user test
#由root用户把test文件的所有者改为user用户
[root@localhost user]# su- user
#切换为user用户
[user@localhost ~]$ chmod 755 test
#user用户由于是test文件的所有者,所以可以修改文件的权限
[user@localhost ~]$ ll test
-rwxr-xr-x 1 user root 0 6月 16 05:37 test
#查看权限

通过这个实验,我们可以确定,如果普通用户是这个文件的所有者,就可以修改文件的权限。



举报

相关推荐

0 条评论