drwxr-xr-x. 2 root root  4096 10 月  1 18:17 3
-rw-r--r--. 1 root root    20 10 月  1 13:01 abc.txt

第一位 -:表示文件类型,- 文件,d 目录,l 软链接;

以下每三位为一组
第一组 rw-:2-4 位表示文件所有者的权限,即用户 user 权限,简称 u
第二组 r--:5-7 位表示文件所有者所属组成员的权限,group 权限,简称 g
第三组 r--: 8-10 位表示所有者所属组之外的用户的权限, other 权限,简称 o

数字 1 :表示 inode ,节点号

第一个 root 表示该文件所有者是 root 用户,第二个 root 代表该文件的所属的组为 root 组

r 读,数字 4 表示;
w 写,数字 2 表示;
x 执行,数字 1 表示;
- 删除,数字 0 表示

数字设定法
rwx 属性则 4+2+1=7;
rw- 属性则 4+2=6;
r-x 属性则 4+1=5

drwxr-xr-x  解释:d(目录)、r(4)、 w(2)、 x(1)  3 权限可以表示为:731
-rw-r--r--  解释:-(文件)、r(4)、 w(2)、 x(1)  3 权限可以表示为:644

[root@hexingxing ~]# chmod 700 abc.txt
-rwx------. 1 root root    20 10 月  1 13:01 abc.txt

// 指定 adc.txt 为 700 的权限 拥有者 7,用户组 0,其他人 0

文件设定权限
+ 添加权限
- 取消权限
= 赋予指定新权限并取消原有权限

实例操作

[root@hexingxing ~]# chmod u=w,g=r,o=r adf.txt
--w-r--r--. 1 root root    23 10 月  1 12:55 adf.txt 

//取消 adf.txt 文件原来的权限并设定为所有者可写,群组和其他人只读

[root@hexingxing ~]# chmod g=w adf.txt
--w--w-r--. 1 root root    23 10 月  1 12:55 adf.txt

//取消 adf.txt 文件群组原来的权限并设定为可写,所有者和其他人不变

[root@hexingxing ~]# chmod o+w adf.txt
--w--w-rw-. 1 root root    23 10 月  1 12:55 adf.txt

//为 adf.txt 文件添加群组可写权限,其他权限不变

 [root@hexingxing ~]# chmod o-r adf.txt
--w--w--w-. 1 root root    23 10 月  1 12:55 adf.txt

//为 adf.txt 文件取消群组可读权限,其他权限不变

[root@hexingxing ~]# chmod a+x adf.txt
--wx-wx-wx. 1 root root    23 10 月  1 12:55 adf.txt

//对 adf.txt 文件的 u,g,o 都添加可执行权限

[root@hexingxing ~]# chmod -R 777 ccc/
drwxrwxrwx 1 root root    23 10 月  1 12:55 ccst
-rwxrwxrwx 1 root root    23 10 月  1 12:55 aye.txt

//对 ccc/ 文件夹下的所有文件和文件夹进行相同的权限变更 (即以递回的方式逐个变更)

[root@hexingxing common]# ll
……
-r--r--r-- 2 hello hello      4096 Oct  5 22:23 sdir
[root@hexingxing common]# chmod a=w sdir
[root@hexingxing common]# ll
……
--w--w--w- 2 hello hello      4096 Oct  5 22:23 sdir

// a=w:相当于同时使用 u=w;g=w;o=w
// 取消 sdir 文件原来的所有权限并设定指定的新权限

[root@hexingxing common]# ll
-rw-r--r-- 1 root  root  255551371 Oct  5 21:45 1.mp4
-rwxr--r-- 1 root  root   28891679 Sep 13 20:13 9.mp4
……
[root@hexingxing common]# chmod --reference 9.mp4 1.mp4
[root@hexingxing common]# ll
total 332764
-rwxr--r-- 1 root  root  255551371 Oct  5 21:45 1.mp4
-rwxr--r-- 1 root  root   28891679 Sep 13 20:13 9.mp4
……

// reference:参考权限 将 9.mp4 的权限属性复制给 1.mp4


友情提示:本站所有文章,如无特殊说明或标注,均为何星星原创发布。与此同时,趋于近年来本站的文章内容频繁被他站盗用与机器采集,现已全局禁用网站文字内容操作,了解详情或转载文章请 点此 继续!

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注