chmod 和chown

2017-04-10  本文已影响32人  lmem

1、chown 中的 -R 参数

修改文件的属主
修改的ll命令的第三四列

[root@localhost yuechaotian]# chown root:root test
[root@localhost yuechaotian]# ll
总用量 8
drwxr-xr-x  3 root root 4096 12月  7 14:52 study
drwxr-xr-x  2 root root 4096 12月  9 21:43 test
[root@localhost yuechaotian]# chown -R yuechaotian:dba test
[root@localhost yuechaotian]# ll
总用量 8
drwxr-xr-x  3 root        root 4096 12月  7 14:52 study
drwxr-xr-x  2 yuechaotian dba  4096 12月  9 21:43 test
[root@localhost yuechaotian]# ll test
总用量 12
-rwxr-xr-x  1 yuechaotian dba 11742 12月  9 21:43 conf.rd 

2. chmod

范例 :

将档案 file1.txt 设为所有人皆可读取 :
chmod ugo+r file1.txt
将档案 file1.txt 设为所有人皆可读取 :
chmod a+r file1.txt
将档案 file1.txt 与 file2.txt 设为该档案拥有者,与其所属同一个群体者可写入,但其他以外的人则不可写入 :
chmod ug+w,o-w file1.txt file2.txt
将 ex1.py 设定为只有该档案拥有者可以执行 :
chmod u+x ex1.py
将目前目录下的所有档案与子目录皆设为任何人可读取 :
chmod -R a+r *
此外chmod也可以用数字来表示权限如 chmod 777 file
语法为:chmod abc file
其中a,b,c各为一个数字,分别表示User、Group、及Other的权限。
r=4,w=2,x=1
若要rwx属性则4+2+1=7;
若要rw-属性则4+2=6;
若要r-x属性则4+1=7。
范例:
chmod a=rwx file

chmod 777 file
效果相同
chmod ug=rwx,o=x file

chmod 771 file
效果相同

上一篇 下一篇

猜你喜欢

热点阅读