话不多说,先了解一下文件的权限阶段:

整个权限描述分为4段
第一段用于描述该文件的类型,可以是常规文件(-)、目录(d)、块设备(b)、链接(l)和字符设备(c)等等
后面三段是文件具体的权限描述信息了,分别是文件主权限、组用户权限和其它用户(UGO)的权限。通过上述三段的组合就可以实现比较复杂的权限控制。比如允许某个用户的文件可以被其它用户读,但是不可以改写和执行等等

RWX解读如下:
依照上面的表格,权限组合就是对应权限值求和,如下:
依照上面的表格,权限组合就是对应权限值求和,如下:
7 = 4 + 2 + 1 读写运行权限
5 = 4 + 1 读和运行权限
4 = 4 只读权限
因此,大家也就明白了 chmod 754 filename 命令的含义了
1、新增一个文件test.txt,并该文件对任何人都没有任何权限:
root@lhb:~# chmod u=,g=,o= test.txt
root@lhb:~# ls -l test.txt
———- 1 root root 0 Nov 30 14:59 test.txt
2、增加属主的rwx权限
root@lhb:~# chmod u=rwx test.txt
root@lhb:~# ls -l test.txt
-rwx—— 1 root root 0 Nov 30 14:59 test.txt
3、增加数组的rwx权限
root@lhb:~# chmod g=rwx test.txt
—-rwx— 1 root root 0 Nov 30 14:59 test.txt
4、增加其他用户的rwx权限
root@lhb:~# chmod o=rwx test.txt
——-rwx 1 root root 0 Nov 30 14:59 test.txt
5、增加所有用户的rwx权限
root@lhb:~# chmod u=rwx,g=rwx,o=rwx test.txt
root@lhb:~# ls -l test.txt
-rwxrwxrwx 1 root root 0 Nov 30 14:59 test.txt
如果使用阿拉伯数组表示的话,对应的:r=4,w=2,x=1
如果单独增加或修改某一权限,可以使用:
图片
Example:
给文件增加X权限:
root@lhb:~# ls -l test.txt
———- 1 root root 0 Nov 30 14:59 test.txt
root@lhb:~# chmod u+x test.txt
root@lhb:~# ls -l test.txt
—x—— 1 root root 0 Nov 30 14:59 test.txt
去掉文件的执行权限:
root@lhb:~# chmod u-x test.txt
root@lhb:~# ls -l test.txt
———- 1 root root 0 Nov 30 14:59 test.txt
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/hz/141679.html