linux 文件权限

#linux 文件权限

[root@master usr]# ll
总用量 60
-rw-r--r--.  1 root root     0 9月  16 11:48 1.txt
dr-xr-xr-x.  2 root root 12288 9月  15 13:23 bin
drwxr-xr-x.  2 root root  4096 9月  23 2011 etc
drwxr-xr-x.  2 root root  4096 9月  23 2011 games
drwxr-xr-x.  3 root root  4096 9月  15 20:28 include
dr-xr-xr-x. 10 root root  4096 9月  15 21:11 lib
dr-xr-xr-x. 26 root root 12288 9月  15 13:23 lib64
drwxr-xr-x.  9 root root  4096 9月  15 20:30 libexec
drwxr-xr-x. 12 root root  4096 9月  15 20:27 local
dr-xr-xr-x.  2 root root  4096 9月  15 21:11 sbin
drwxr-xr-x. 64 root root  4096 9月  15 13:23 share
drwxr-xr-x.  4 root root  4096 9月  15 20:27 src
lrwxrwxrwx.  1 root root    10 9月  15 20:27 tmp -> ../var/tmp
权限    连接   所有者    用户组    文件容量   修改日期      文件名

-rw-r--r--从左到右十个字符

r :可读 w:可写 x:可执行 -:没有权限

从左至右用0-9这些数字来表示:
(1)0首位表示类型
在Linux中第一个字符代表这个文件是目录、文件或链接文件等等
- 代表文件
 d 代表目录
 c 字符流,装置文件里面的串行端口设备,例如键盘、鼠标(一次性读取装置)
 s socket
 p 管道
 l 链接文档(link file);
 b 设备文件,装置文件里面的可供储存的接口设备(可随机存取装置)
(2)第1-3位确定属主(该文件的所有者)拥有该文件的权限。---User
(3)第4-6位确定属组(所有者的同组用户)拥有该文件的权限,---Group
(4)第7-9位确定其他用户拥有该文件的权限 ---Other
  • chmod改变权限
    chmod [{ugoa}{+-=}{rwx}] [文件或目录] [mode=421 ] [文件或目录]
改变文件或者目录权限
文件: r-查看;w-修改;x-执行文件
目录: r-列出目录内容;w-在目录中创建和删除;x-进入目录
删除一个文件的前提条件:该文件所在的目录有写权限,你才能删除该文件。

符号类型改变权限:

u 属主 + 加入
g 属组 - 除去
o其他人 = 设置
a所有人

[root@master usr]# ll
-rw-r--r--.  1 root root     0 9月  16 11:48 1.txt
[root@master usr]# chmod u+x 1.txt 
[root@master usr]# ll
-rwxr--r--.  1 root root     0 9月  16 11:48 1.txt
[root@master usr]# chmod u-r 1.txt   
[root@master usr]# ll
--wxr--r--.  1 root root     0 9月  16 11:48 1.txt
[root@master usr]# chmod g+w 1.txt  
[root@master usr]# ll
--wxrw-r--.  1 root root     0 9月  16 11:48 1.txt
[root@master usr]# chmod o+w 1.txt  
[root@master usr]# ll
--wxrw-rw-.  1 root root     0 9月  16 11:48 1.txt
[root@master usr]# ll
--wxrw--w-.  1 root root     0 9月  16 11:48 1.txt
[root@master usr]# chmod a+r 1.txt
[root@master usr]# ll
-rwxrw-rw-.  1 root root     0 9月  16 11:48 1.txt

数字类型改变权限:
文件权限字符为[-rwxrwxrwx]九个权限三个为一组,可用数字代表各个权限
一组权限用二进制表示

r   w   x
1   0   0   = 4
1   1   1   = 7
0   0   1   = 1
....
r=4   
w=2   
x=1
[root@master usr]# chmod 777 1.txt
[root@master usr]# ll
-rwxrwxrwx.  1 root root     0 9月  16 11:48 1.txt
[root@master usr]# chmod 666 1.txt
[root@master usr]# ll
-rw-rw-rw-.  1 root root     0 9月  16 11:48 1.txt
[root@master usr]# chmod 555 1.txt
[root@master usr]# ll
-r-xr-xr-x.  1 root root     0 9月  16 11:48 1.txt
[root@master usr]# chmod 333 1.txt
[root@master usr]# ll
--wx-wx-wx.  1 root root     0 9月  16 11:48 1.txt
[root@master usr]# chmod 111 1.txt
[root@master usr]# ll
---x--x--x.  1 root root     0 9月  16 11:48 1.txt
[root@master usr]# chmod 753 1.txt  
[root@master usr]# ll
-rwxr-x-wx.  1 root root     0 9月  16 11:48 1.txt
  • *chown改变所有者
    chown [最终用户] [文件或目录] (功能描述:改变文件或者目录的所有者)
[root@master usr]# ll
-rwxr-x-wx.  1 root root     0 9月  16 11:48 1.txt
[root@master usr]# chown tom 1.txt 
[root@master usr]# ll
-rwxr-x-wx.  1 tom  root     0 9月  16 11:48 1.txt
  • *** chgrp改变所属组**
    chgrp [最终用户组] [文件或目录] (功能描述:改变文件或者目录的所属组)
[root@master usr]# ll
-rwxr-x-wx.  1 tom  root     0 9月  16 11:48 1.txt
[root@master usr]# chgrp death 1.txt 
[root@master usr]# ll
-rwxr-x-wx.  1 tom  death     0 9月  16 11:48 1.txt
  • *** 改变所属主和所属组**
chown lisi:lisi test/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值