linux - umask

# 1. 我创建了一个文件或者文件夹,它们的默认权限是怎样的呢?先尝试一下:
[yuechaotian@localhost ~]$ pwd
/home/yuechaotian
[yuechaotian@localhost ~]$ mkdir test
[yuechaotian@localhost ~]$ touch test.txt
[yuechaotian@localhost ~]$ ll
总用量 8
drwx--x--x 3 root root 4096 12月 7 14:52 study
drwxrwxr-x 2 yuechaotian yuechaotian 4096 12月 9 22:18 test
-rw-rw-r-- 1 yuechaotian yuechaotian 0 12月 9 22:18 test.txt # 2. 目录test的权限被设置为775,文件test.txt的权限被设置为 664.这是由 umask 指定的.
[yuechaotian@localhost ~]$ umask
0002
umask指定了创建目录或文件时,默认需要取消的权限.目录默认情况下的权限是777,文件默认情况下的权限是666.新创建的目录默认权限为777-umask,文件默认权限为666-umask.而在上面的测试中,umask为002,所以会出现上面的权限设置 # 3. 比如设置 umask 为000,重新创建一下目录和权限,可以看到目录 test 的权限被设置为777,文件test.txt的权限被设置为666
[yuechaotian@localhost ~]$ rm -r t*
[yuechaotian@localhost ~]$ umask 000
[yuechaotian@localhost ~]$ umask
0000
[yuechaotian@localhost ~]$ mkdir test
[yuechaotian@localhost ~]$ touch test.txt
[yuechaotian@localhost ~]$ ll
总用量 8
drwx--x--x 3 root root 4096 12月 7 14:52 study
drwxrwxrwx 2 yuechaotian yuechaotian 4096 12月 9 22:27 test
-rw-rw-rw- 1 yuechaotian yuechaotian 0 12月 9 22:27 test.txt # 4. umask可以在/etc/bashrc中修改.默认情况下,root的umask为022,一般用户为002.
因为写权限很重要,所以一般用户要取消掉其他组成员的写权限(002);而由于root用户的特殊性,连与它同组的其他用户的写权限也被取消掉了(022).
[yuechaotian@localhost ~]$ head -12 /etc/bashrc | tail -5
if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then
umask 002
else
umask 022
fi
标签: linuxumask
------分隔线----------------------------
· 首页 · 注册

百鸣[Baiming.org]欢迎您 百鸣[Baiming.org]欢迎您~