关键词:chmod 一定要记住是mo不是om
首先要知道修改权限有两种方法,字母法和数字法
然后是查看权限的方法 ls -l 文件名
字母法记住这几个角色
u
文件的所有者
属主
g
文件的用户组
属组
o
其他用户
其他
a
所有用户者
格式:chomd 角色 +/-/= 权限 文件名
+ 添加权限 -减少权限 =覆盖原来的权限
数字法: r 读 4 w 写 2 x 执行 1
格式:chomd 属主,数组,其他 文件名
属主,数组,其他上写数字,0-7总共八个,0是没有权限,7是所有权限
读 写 执行 各自代表的数字相加就是所拥有的权限
比如: 3 就是写和执行 4只有读 5是读和执行
接下来练习几个就能完全掌握了
1.创建文件a,查看a的权限,修改a的权限为属主读写执行数组读执行其他读
[leq@localhost leq]$ touch a
[leq@localhost leq]$ ls -l a
-rw-rw-r--. 1 leq leq 0 9月 23 11:56 a
[leq@localhost leq]$ chmod u=rwx,g=rx,o=r a
[leq@localhost leq]$ ls -l a
-rwxr-xr--. 1 leq leq 0 9月 23 11:56 a
2.用数字法和字母法修改a的角色拥有所有的权限
[leq@localhost leq]$ chmod 777 a
[leq@localhost leq]$ ls -l a
-rwxrwxrwx. 1 leq leq 0 9月 23 11:56 a
[leq@localhost leq]$ chmod a=rwx a
[leq@localhost leq]$ ls -l a
-rwxrwxrwx. 1 leq leq 0 9月 23 11:56 a
3.创建a目录和b文件,将a目录和b文件都拥有所有的权限,删除a目录属组和其他写的权限,
将b文件的其他权限修改为执行
[leq@localhost leq]$ mkdir a|touch b
[leq@localhost leq]$ ls
a b
[leq@localhost leq]$ ls -l
总用量 0
drwxrwxr-x. 2 leq leq 6 9月 23 14:39 a
-rw-rw-r--. 1 leq leq 0 9月 23 14:39 b
[leq@localhost leq]$ chmod 777 a|chmod a+rwx b
[leq@localhost leq]$ ls -l
总用量 0
drwxrwxrwx. 2 leq leq 6 9月 23 14:39 a
-rwxrwxrwx. 1 leq leq 0 9月 23 14:39 b
[leq@localhost leq]$ chmod g-w,o-w a|chmod 771 b
[leq@localhost leq]$ ls -l
总用量 0
drwxr-xr-x. 2 leq leq 6 9月 23 14:39 a
-rwxrwx--x. 1 leq leq 0 9月 23 14:39 b