chmod 更改权限
rwx数字分别表示 4 2 1,则rwx=7 r-x=5 r--=4 等等
1、查看文件或目录详细信息
[root@wy ~]# ls -l
总用量 48
-rw-r--r-- 1 root root 0 9月 21 03:06 1.txt
-rw-------. 1 root root 1460 9月 9 02:39 anaconda-ks.cfg
-rw-r--r--. 1 root root 29745 9月 9 02:39 install.log
-rw-r--r--. 1 root root 6995 9月 9 02:37 install.log.syslog
2、修改 1.txt 的权限
[root@wy ~]# chmod 744 1.txt
[root@wy ~]# ls -l
总用量 48
-rwxr--r-- 1 root root 0 9月 21 03:06 1.txt
3、还可以这样修改
[root@wy ~]# chmod u-x 1.txt
[root@wy ~]# ls -l 1.txt
-rw-r--r-- 1 root root 0 9月 21 2016 1.txt
[root@wy ~]# chmod u+x,g+w,o-r 1.txt
[root@wy ~]# ls -l 1.txt
-rwxrw---- 1 root root 0 9月 21 2016 1.txt
4、用 a 来代表所有(ugo)
[root@wy ~]# chmod a+r 1.txt
[root@wy ~]# ls -l 1.txt
-rwxrw-r-- 1 root root 0 9月 21 2016 1.txt
5、继承权限(也就是一个目录下的子目录继承父目录的权限)
[root@wy ~]# ls -l 111
总用量 4
drwxr-xr-x 2 root root 4096 9月 20 19:55 222
-rw-r--r-- 1 root root 0 9月 20 19:54 22.txt
[root@wy ~]# chmod -R 700 111
[root@wy ~]# ls -l 111
总用量 4
drwx------ 2 root root 4096 9月 20 19:55 222
-rwx------ 1 root root 0 9月 20 19:54 22.txt
6、查看当前用户的 umask值
[root@wy ~]# umask
0022
它的作用是用来规定我们默认的目录和文件的权限
7、查看目录与文件的默认权限
[root@wy ~]# mkdir 123
[root@wy ~]# ls -ld 123
drwxr-xr-x 2 root root 4096 9月 20 20:10 123 #目录默认是755
[root@wy ~]# touch 123.txt
[root@wy ~]# ls -l 123.txt
-rw-r--r-- 1 root root 0 9月 20 20:10 123.txt #文件默认是644
默认权限是通过umask来规定的,来推演出来的
linux下所有的目录的权限必须要有 x 权限,为什么要有 x 权限呢,可以这样理解,目录呢它是一个特殊的文件,那这个文件是可以存放东西的,作为一个目录的话,我们应该能够让人去进入到这个目录下去,进去然后再去更改或者创建或者删除等等这样的操作,前提是我们必须要进入,可想而知,进入一个文件,这是不是一个动作,一种行为,这种行为呢,让它能够让我们去执行来行,它必须可执行,我们才能做这个动作,所以目录必须要有 x 权限,不然,我们不可以进去。而文档就没有必要有执行权限了。所以这时,我们就有了一个推论的过程,umask是0022,通常情况下,只用后三位022,即--- -w- -w- ,所以目录的推演过程是:(rwx rwx rwx)-(--- -w- -w-)=rwx r-x r-x=755;同理文件(没必要有执行权限)的推演过程:(rw- rw- rw-)-(--- -w- -w-)=rw- r-- r--=644
8、改变umask值
[root@wy ~]# umask 0011
[root@wy ~]# umask
0011
随之默认的目录和文件的权限也会改变
[root@wy ~]# mkdir 1111
[root@wy ~]# ls -ld 1111
drwxrw-rw- 2 root root 4096 9月 20 20:29 1111
[root@wy ~]# touch 1111.txt
[root@wy ~]# ls -l 1111.txt
-rw-rw-rw- 1 root root 0 9月 20 20:29 1111.txt
本文出自 “linux” 博客,转载请与作者联系!
原文:http://warm51fun.blog.51cto.com/3884274/1891536