- [[email protected]~]# ls -l总用量 8-rw-r--r--. 1 root root 0 6月 8 14:16 2.txt
- -rw-------. 1 root root 7728 6月 6 22:11 anaconda-ks.cfg.1
这一段, 除了第一位的
- -rw-r--r--.
表示的是文件类型 , 最后一位的
- -
表示的是该文件是否受 SELinux 限制 *(SELinux 如果 disabled 后, 新建的文件 / 目录, 就不会有这个点, 否则就会有)*, 中间的九位, 表示的就是该文件或者文件夹的权限 .
- .
前三位表示的是文件 / 目录的所有者的权限.
中间三位表示的是文件 / 目录的所属组内所有成员的权限
最后三位表示的出路所有者和所属组外, 其他用户对该文件 / 目录的权限.
r : read --> 读 w : write --> 写 x : execute --> 执行
- -rw-r--r--. 1 root root 0 6月 8 14:16 2.txt
root 用户对 2.txt 文件有 r 和 w 权限, 没有 x 权限 root 用户组对 2.txt 文件有 r 权限, 没有 w 和 x 权限 其他用户对 2.txt 文件有 r 权限, 没有 w 和 x 权限
x --> 2 的 0 次方 w --> 2 的 1 次方 r --> 2 的 2 次方 每一段的数字相加, 得到对应用户对该文件的权限数字
等于 6 4 4
- rw-r--r--
- [[email protected]~]# chmod 700 2.txt[[email protected]~]# ls -l总用量 8-rwx------. 1 root root 0 6月 8 14:16 2.txt
- -rw-------. 1 root root 7728 6月 6 22:11 anaconda-ks.cfg.1
- 2. 使用r,
- w,
- x表示的权限
- [[email protected] ~]# chmod u = rw,
- g = rx,
- o = x 2.txt[[email protected] ~]# ls - l总用量 8 - rw - r - x--x. 1 root root 0 6月 8 14 : 16 2.txt - rw-------. 1 root root 7728 6月 6 22 : 11 anaconda - ks.cfg.1
- > u --> user > g --> group > o --> other * *==特别注意 : 使用这种方式,
- 不能写成u = rw - ,
- g = r - x,
- o = --x,
- 中间不能出现 - ,
- 虽然有时候可以通过,
- 不过这样写是不合理的.因为后面会看到,
- 有一种修改权限的方式,
- 是通过使用"+"或"-"号,
- 来控制权限的增加和减少的. == **3. 使用 + -号来控制权限
- [[email protected]~]# chmod a+x 2.txt[[email protected]~]# ls -l总用量 8-rwxr-x--x. 1 root root 0 6月 8 14:16 2.txt
- > a --> all ,
- a + x ,
- 所有用户对文件 / 目录添加x权限.
- [[email protected]~]# chmod a-r 2.txt[[email protected]~]# ls -l总用量 8--wx--x--x. 1 root root 0 6月 8 14:16 2.txt
- > 所有用户对文件/目录减少r权限
- [[email protected]~]# chmod u+r 2.txt[[email protected]~]# ls -l总用量 8-rwx--x--x. 1 root root 0 6月 8 14:16 2.txt
- > 单独对user,
- 增加r权限.
选项
- -R
修改权限, 对目录内所有文件, 子目录都生效
- [[email protected]~]# tree /tmp/allinlinux//tmp/allinlinux/
- └── 1.txt0 directories, 1 file
- [[email protected]~]# ls -l /tmp/allinlinux/总用量 0-rw-r--r--. 1 root root 0 6月 8 14:58 1.txt
- [[email protected]~]# ls -l /tmp/allinlinux/1.txt -rw-r--r--. 1 root root 0 6月 8 14:58 /tmp/allinlinux/1.txt
/tmp/allinlinux 目录下有一个 1.txt 文件 allinlinux / 目录的权限是
1.txt 文件的权限是
- rw-r--r--
- rw-r--r--
- [[email protected]~]# chmod -R 777 /tmp/allinlinux/[[email protected]~]# ls -l /tmp/allinlinux/总用量 0-rwxrwxrwx. 1 root root 0 6月 8 14:58 1.txt
- [[email protected]~]# ls -l /tmp/allinlinux/1.txt -rwxrwxrwx. 1 root root 0 6月 8 14:58 /tmp/allinlinux/1.txt
/allinlinux / 目录和其内的文件的权限, 都更改过来了.
来源: http://www.bubuko.com/infodetail-2111554.html