linux的chmod

1. chomd 改变文件权限

chmod u
g
o
a
+(添加)
-(去除)
=(设置)
r
w
x
dir/file

chmod常见写法

1. 将档案 file1.txt 设为所有人皆可读取 : 

chmod ugo+r file1.txt  

2. 将档案 file1.txt 设为所有人皆可读取 : 

chmod a+r file1.txt  

3. 将档案 file1.txt 与 file2.txt 设为该档案拥有者,与其所属同一个群体者可写入,但其他以外的人则不可写入 : 

chmod ug+w,o-w file1.txt file2.txt  

4. 将 ex1.py 设定为只有该档案拥有者可以执行 : 

chmod u+x ex1.py  

5. 将目前目录下的所有档案与子目录皆设为任何人可读取 : 

chmod -R a+r *  

6. 数字写法

chmod 755 [fileName]   #所有者读写执行,用户组和其他,只有读和执行权限

chmod 777 [fileName]   #所有人都有读写和执行权限

2. chown 改变文件属主和属组

用来更改某个目录或文件的用户名和用户组的
chown 用户名:组名 文件路径(可以是就对路径也可以是相对路径)
例1:

chown root:root /tmp/tmp1

就是把tmp下的tmp1的用户名和用户组改成root和root(只修改了tmp1的属组).
例2:

chown -R root:root /tmp/tmp1

就是把tmp下的tmp1下的所有文件的属组都改成root和root。

3. chgrp 改变文件属组

# 将/usr/test及其子目录下的所有文件的用户组改为zhangsan

chgrp -R zhangsan /usr/test

 

参考:https://www.cnblogs.com/LinuxBlogs/p/4378209.html

        https://www.cnblogs.com/huxinga/p/9946464.html 

posted @ 2020-07-24 14:04  全玉  阅读(521)  评论(0编辑  收藏  举报