设置Linux文件和目录权限的方法


1、字符表示法

类型 操作 权限

u + r

g - w

o = x

a

类型代表修改权限的对象,u表示文件的用户,g表示文件所有者的群组,o表示非用户组用户,a表示ugo

操作 + 表示增加权限,- 表示减少权限,= 表示赋予权限

权限 r 表示只读,w 表示可写,x 表示可执行

[root@localhost ~] # mkdir perm

[root@localhost ~] # cd perm

[root@localhost perm] # mkdir test

[root@localhost perm] # cd test

[root@localhost test] # touch test1

[root@localhost test] # touch test2

以下是测试命令,具体见下图

chmod u-w test

chmod g+w test

chmod ug+w test

chmod ugo-x test

chmod a+x test

chmod o=w test

chmod a= perm

chmod -R a+rwx perm

\

2、数字表示法

权限 数字

r 4

w 2

x 1

- 0

例如rwx数字表示即4+2+1=7,实际上这是二进制表示,rwx三位bit,111,即7

例子:

chmod 577 test

chmod 555 test

chmod -R 754 test //-R 参数意为递归

\

 

相关内容