文件和目录权限chmod、更改所有者和所属组chown、umask、隐藏权限lsattr/chattr

文件和目录权限chmod

1、

权限范围:

u :目录或者文件的当前的用户

g :目录或者文件的当前的群组

o :除了目录或者文件的当前用户或群组之外的用户或者群组

a :所有的用户及群组


权限代号:

r :读权限,用数字4表示

w :写权限,用数字2表示

x :执行权限,用数字1表示

- :删除权限,用数字0表示

s :特殊权限 

[root@test ~]# chmod 700 anaconda-ks.cfg 

You have new mail in /var/spool/mail/root

[root@test ~]# ls -la anaconda-ks.cfg 

-rwx------. 1 root root 1096 Sep  3 07:27 anaconda-ks.cfg


-R:表示递归

[root@test ~]# chmod 755 -R /opt/

[root@test ~]# ls -la /opt/

total 286660

drwxr-xr-x.  7 root root      4096 Oct 23 09:55 .

dr-xr-xr-x. 28 root root      4096 Oct 20 16:41 ..

-rwxr-xr-x   1 test test      6555 Oct 16 17:13 percona-release-0.1-4.noarch.rpm

drwxr-xr-x  17 test test      4096 Oct 10 22:48 Python-2.7.6


更改所有者和所属组chown

-R:表示有目录的情况下

[root@test ~]# chown -R root.root *

You have new mail in /var/spool/mail/root

[root@test ~]# ll

total 2352

-rwx------. 1 root root    1096 Sep  3 07:27 anaconda-ks.cfg

drwxr-xr-x  3 root root    4096 Oct 11 05:01 conf

-rw-r--r--  1 root root    3523 Sep 18 15:12 file.txt

-rw-r--r--  1 root root 1595408 Nov  7  2016 get-pip.py

-rw-r--r--. 1 root root    9795 Sep  3 07:27 install.log

-rw-r--r--. 1 root root    3091 Sep  3 07:26 install.log.syslog


umask

1、查看

[root@test ~]# umask 

0022


2、当umask为偶数时:

默认情况下的umask值是022(可以用umask命令查看),此时你建立的文件默认权限是644(6-0,6-2,6-2),建立的目录的默认权限是755(7-0,7-2,7-2)

3、当umask为基数时:
相减后加上1

如:umask 051

666 - 051=615;加上1:变为626的权限

文件:

[root@test ~]# touch 1.txt

[root@test ~]# ls -la 1.txt 

-rw--w-rw- 1 root root 0 Oct 23 11:41 1.txt


文件夹(777-051=726):

[root@test ~]# ls -ld tt/

drwx-w-rw- 2 root root 4096 Oct 23 11:44 tt/


隐藏权限lsattr/chattr

charrt

改变文件属性

-i:不能编更改文件和目录,即使root也不行

[root@test ~]# chmod 777 1.txt

chmod: changing permissions of `1.txt': Operation not permitted

-a:只能追加操作,不能直接编辑文件vi

[root@test ~]# echo '123123' >> 1.txt

lsattr 1.txt

查看权限

取消:

chattr -i  1.txt








本文转自方向对了,就不怕路远了!51CTO博客,原文链接:http://blog.51cto.com/jacksoner/1975185 ,如需转载请自行联系原作者





上一篇:Some Background - 1


下一篇:2.14 文件和目录权限chmod 2.15 更改所有者和所属组chown 2.16 umask 2.17 隐藏权限lsattr/chattr