文件权限

发布时间 2023-10-29 08:59:45作者: q_7

一:文件和目录的权限的理解

1:linux的文件和目录的权限

linux的访问文件的权限为,可读(r),可写(w),可执行(x)

权限 文件 目录
r 可以读取该文件 可以列出该文件的内容
w 可以编辑该文件 可以删除,重命名等操作
x 可以执行该文件 可以进入该文件

 

linux访问文件的用户有三种

文件的创建者(所有者)---对应 u

文件的属组----对应 g

其他用户----对应 o

a=ugo

2:查看文件的权限 ll

#查看etc的权限
[root@server /]# ll /etc/ -d
drwxr-xr-x. 140 root root 8192 10月 28 20:12 /etc/

d---代表的是文件的类型
后面的三个为一组
第一组对应 所有者的权限
第二组对应 用户组的权限
第三组对应 其他用户的权限

 

二:管理文件和目录的权限

1:字符设定法

就是用字母来设置权限,加减来添加或者删除权限

命令的格式

chmod   选项  符号  权限 文件名 

选项:

u:代表用户

g:代表用户组

o:代表其他的用户

a:代表所有的用户

符号:

+:添加权限

-:减少权限

=:等于这个权限

权限:

r:读的权限

w:写的权限

x:执行的权限

 

(1)修改文件的权限

[root@server mnt]# ll
总用量 0
-rw-r--r--. 1 root root 0 10月 28 21:46 11.txt
[root@server mnt]# 
#添加用户组和其他用户有写的权限(修改多个多个类型的用户,用逗号隔开)
[root@server mnt]# chmod g+w,o+w 11.txt 
[root@server mnt]# ll
总用量 0
-rw-rw-rw-. 1 root root 0 10月 28 21:46 11.txt
[root@server mnt]# 
#删除其他用户读的权限
[root@server mnt]# chmod o-w 11.txt 
[root@server mnt]# ll
总用量 0
-rw-rw-r--. 1 root root 0 10月 28 21:46 11.txt
[root@server mnt]# 
#所有用户只有读的权限
[root@server mnt]# chmod a=r 11.txt 
[root@server mnt]# ll
总用量 0
-r--r--r--. 1 root root 0 10月 28 21:46 11.txt
[root@server mnt]# 
#多级目录权限的设置,读写的权限
[root@server mnt]# ll -R
.:
总用量 0
-r--r--r--. 1 root root  0 10月 28 21:46 11.txt
drwxr-xr-x. 2 root root 20 10月 28 21:54 test

./test:
总用量 0
-rw-r--r--. 1 root root 0 10月 28 21:54 22.txt
[root@server mnt]# chmod u+rw,g+rw test/ -R
[root@server mnt]# ll -R
.:
总用量 0
-r--r--r--. 1 root root  0 10月 28 21:46 11.txt
drwxrwxr-x. 2 root root 20 10月 28 21:54 test

./test:
总用量 0
-rw-rw-r--. 1 root root 0 10月 28 21:54 22.txt
[root@server mnt]#