Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1521675
  • 博文数量: 289
  • 博客积分: 11086
  • 博客等级: 上将
  • 技术积分: 3291
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-22 17:06
个人简介

徐小玉的博客。

文章分类

全部博文(289)

文章存档

2023年(6)

2022年(1)

2021年(2)

2020年(9)

2019年(9)

2018年(6)

2017年(10)

2016年(10)

2014年(3)

2013年(4)

2011年(12)

2010年(16)

2009年(14)

2008年(119)

2007年(48)

2006年(20)

我的朋友

分类: LINUX

2019-11-20 10:14:30

Default umask Value

The user file-creation mode mask (umask) is use to determine the file permission for newly created files. It can be used to control the default file permission for new files. It is a four-digit octal number.


umask设置的是权限“补码”,而chmod设置的是文件权限码。一般我们系统默认反码指定的是022(/etc/bashrc,但各系统会有不同。MAC OS ?)


Umask 给出文件和目录的初始权限。它与系统默认的赋予权限相减,获得初始权限。然后通过chmod 来赋予用户渴望的权限。


文件默认最大权限为666(rw-rw-rw-)系统默认没有赋予它最高的执行权限。

目录默认最大权限为777(rwxrwxrwx)。目前的x代表可以进入目录。


假如目前的umask是022

mc-Wed Nov 20-08:57$ umask 

0022 

其中的第一个0,有人说是八进制,但也有说是特殊含义字符,所以本人目前疑惑中....可以确定的是,它对普通用处关系不大,因此留着以后机会合适再钻研。


下面这段话,直接拷贝自apple support,不解释。

A three-digit number can represent the POSIX permissions for a file. You might see permissions represented this way when you view them from Terminal. Each digit is between zero and seven. When you create a file, the umask value is subtracted from a default value (usually 666 for files and 777 for folders) to determine the permissions for the new file or folder.

For example, a default umask of 022 sets permissions of 644 on new files and 755 on new folders. These permissions allow groups and other users to read the files and open the folders, but only the owner can make changes. 

Be sure you understand umasks before proceeding. If you set a umask incorrectly, you might inadvertently lose access to files or grant access to other users. See the MODES section of the chmod(1) manual page for more information.

You can set the umask in several different locations. Each location affects different apps.

创建一个文件,默认初始权限是666,那建成这个文件的权限应该是644(rw-r--r--)( 666-022 ; rw-rw-rw- ----w--w- )

 

而目录的权限为755。因为目录的默认初始是777,umask是022,777-022=755

drwxr-xr-x    2 mc  staff        64 Nov 20 09:08 file_test 


用umask -s可以以符号形式显示创建目录的初始权限: 

也就是755


Unmask的值可以设置:

$ umask 026

——r-wr-

这时再建目录和文件: 


 

目录权限为751( 777-026)

文件权限为640(666-026)

这都是初始权限,想要什么权限,可以用 chmod chown来修改。

- Change access permissions.

- Change file owner and group.

阅读(5878) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~