修改文件的权限(linux篇)

发布于:2024-06-26 ⋅ 阅读:(156) ⋅ 点赞:(0)

1.在yl用户下创建一个demo.txt文件

[root@localhost ~]# su yl
[yl@localhost root]$ cd
[yl@localhost ~]$ cd Desktop/
[yl@localhost Desktop]$ ls
[yl@localhost Desktop]$ vim demo.txt

 填入一些信息进行保存

2.查看文件信息以及所对应的组

[yl@localhost Desktop]$ ll
总用量 4
-rw-rw-r--. 1 yl yl 15 6月  18 16:13 demo.txt
[yl@localhost Desktop]$

3.切换会root用户

切换回去是没有文件信息,接下来将刚刚在yl中的创建的demo.txt文件复制到root用户当中

4.复制demo.txt文件到root用户中并查看拷贝的信息

cp -a 源文件路径 新文件路径(这里加-a是原封不动的将之前的属性全部拷贝过来)

这里拷贝过来的所有信息都是一模一样的

[root@localhost Desktop]# cp -a /home/yl/Desktop/demo.txt .
[root@localhost Desktop]# ls
demo.txt
[root@localhost Desktop]# ll
总用量 4
-rw-rw-r--. 1 yl yl 15 6月  18 16:13 demo.txt
[root@localhost Desktop]#

由于这里使用到了root用户,所以这里可以直接用vim命令更改,没有达到我们想要的目的

所以更换为hsyl用户,再将前面的步骤再做一遍

5.已经将yl用户中的demo.txt文件拷贝到了hsyl用户当中

[hsyl@localhost ~]$ sudo cp -a /home/yl/demo.txt .
[sudo] hsyl 的密码:
[hsyl@localhost ~]$ ls
demo.txt
[hsyl@localhost ~]$ ll
总用量 4
-rw-rw-r--. 1 yl yl 15 6月  18 16:49 demo.txt
[hsyl@localhost ~]$

对比下去可以看到两者用户创建文件的用户和用户组的不同

6.chmod:用于权限的修改

o:其他用户==》chmod o+w demo.txt 给demo.txt文件的其他用户添加写入权限

u:所有者==》chmod u+x demo.txt 给demo.txt文件的所有者用户添加执行的权限

g:所属组==》chomd g-w demo.txt 给demo.txt文件所属的组删除写入的权限

a:全部==》chmod a-r demo.txt 让demo.txt文件所有的属性都删除读的权限


网站公告

今日签到

点亮在社区的每一天
去签到