文件管理

2019-08-07  本文已影响0人  a幕城

昨日回顾

方式一: ugo user group other all=ugo
方式二: number r=4 w=2 x=1 -=0
[root@bgx ~]# touch file #创建文件 [root@bgx ~]# chmod a=rwx file #给所有人添 加读写执行权限
[root@bgx ~]# chmod a=-rwx file #取消所有的 权限 [root@bgx ~]# chmod u=rwx,g=rw,o=- file #属主读写执 行,属组读写,其他人无权限 [root@bgx ~]# chmod ug=rwx,o=r file #属主属组读 写执行,其他人读权限
[root@bgx ~]# ll file -rwxrw-r-- 1 root root 0 Apr 13 03:29 file

针对文件最高设定为 777 但是一般都是666

针对 hr 部门的访问目录/home/hr 设置权限,要求如下:
1.root 用户和 hr 组的员工可以读、写、执行
2.其他用户没有任何权限

1.设定属主(读写) 属组(读)权限 其他人(无) rw-r------ 翻译为数字 640

[root@oldboyedu opt]# chmod 640 1.txt [root@oldboyedu opt]# ll 1.txt -rw-r-----. 1 oldboy root 8 Aug 7 10:07 1.txt

2. 设定属主(读写) 属组(无)权限 其他人(无) [root@oldboyedu opt]# chmod 600 1.txt [root@oldboyedu opt]# ll total 4 -rw-------. 1 oldboy root 8 Aug 7 10:07 1.txt

针对目录设定权限: 777 #选项: -R递归修改 [root@bgx ~]# mkdir dir [root@bgx ~]# chmod 777 dir/ #修改目录允许所有人访问

[root@bgx ~]# chmod -R 755 dir/ #修改目录及子目录权限
[root@bgx ~]# ll -d dir/ drwxr-xr-x 2 root root 6 Apr 13 03:34 dir/
[root@bgx ~]# groupadd hr [root@bgx ~]# useradd hr01 -G hr [root@bgx ~]# useradd hr02 -G hr
[root@bgx ~]# mkdir /home/hr [root@bgx ~]# chgrp hr /home/hr [root@bgx ~]# chmod 770 /home/hr
[root@bgx ~]# ll -d /home/hr drwxrwx--- 2 root hr 6 Apr 13 03:26 /home/hr

3 权限验证

针对文件:
r: 能读取文件内容 cat head less tail more
w: 能写入文件 (不能看)
vim x: 能执行文件(如果没有r权限,单有x 没有用)
rw: 能查看文件,能编辑文件. 不能执行.不能删除,不能移动,不能复 制 (1) rx: 能查看文件,不能编辑,能执行. 不能删除,不能移动,不能复制 (2) rwx: 能查看文件,能编辑文件,能执行. 不能删除\移动\复制 --->使用 较少
针对目录的权限:
r: 具有浏览目录的权限,无法进入目录,使用ls 查看目录下的文件会 报错,但会显示文件名称, 如果使用 ls-l 只能看到文件名称,其他的 全部无法查看 w: 什么权限也没有 x: 能进入目录,其他什么也没有
rx: 能进入目录,能查看目录下的文件,至于操作文件,需要看文件本 身的权限. (1) rw:
rwx: 如果目录赋予了w权限,则该目录下的文件可以复制\删除\移 动\修改
文件使用最多: rw=6 rx=5 644
目录使用最多: rx = 5 755

3 属主和属组变更

&& touch dir/file

示例1: 修改所属主为bin [root@bgx ~]# chown bin dir/

示例2: 修改所属组为adm [root@bgx ~]# chown .adm dir/

示例3: 递归修改目录及目录下的所有文件属主和属组 [root@bgx ~]# chown -R root.root dir/

上一篇 下一篇

猜你喜欢

热点阅读