Linux下umask命令的用法

umask设置新文档的默认属性,有字符表达形式(Symbolic values)和八进制表达形式(Octal values)两种。

1 为所有用户统一修改默认的umask
You can setup umask in /etc/bashrc or /etc/profile file for all users. By default most Linux distro set it to 0022 (022) or 0002 (002). Open /etc/profile or ~/.bashrc file, enter:

# vi /etc/profile

OR

$ vi ~/.bashrc

Append/modify following line to setup a new umask:

umask 022

Save and close the file. Changes will take effect after next login. All UNIX users can override the system umask defaults in their /etc/profile file, ~/.profile (Korn / Bourne shell) ~/.cshrc file (C shells), ~/.bash_profile (Bash shell) or ~/.login file (defines the user’s environment at login).

2 常用的umask

1)A umask of 022 allows only you to write data, but anyone can read data.
2)A umask of 077 is good for a completely private system. No other user can read or write your data if umask is set to 077.
3)A umask of 002 is good when you share data with other users in the same group. Members of your group can create and modify data files; those outside your group can read data file, but cannot modify it.
4)Set your umask to 007 to completely exclude users who are not group members.

3 数字的详细含义
Octal value : Permission
0 : read, write and execute
1 : read and write
2 : read and execute
3 : read only
4 : write and execute
5 : write only
6 : execute only
7 : no permissions
这里写图片描述

To set the umask 077 type the following command at shell prompt:

$ umask 077
$ mkdir dir1
$ touch file
$ ls -ld dir1 file

Sample outputs:

drwx------ 2 vivek vivek 4096 2011-03-04 02:05 dir1
-rw------- 1 vivek vivek    0 2011-03-04 02:05 file

理解上:
**(1)讲umask看做【Owner,Group,Others】三个对象的原始默认属性中需要去掉哪些权限(r=4, w=2, x=1, -=0)。例如,umask=003则表示Owner不用去掉任何权限,Group不需要去掉任何权限,Others需要去掉2+1即为w和x权限。
(2)档案的原始默认属性是666(-rw-rw-rw-),目录的原始默认属性为777(drwxrwxrwx)。**


4 用字符表达形式设置umask
r : read
w : write
x : execute
u : User ownership (user who owns the file)
g : group ownership (the permissions granted to other users who are
members of the file’s group)
o : other ownership (the permissions granted to users that are in
neither of the two preceding categories)

The following command will set umask to 077 i.e. a umask set to u=rwx,g=,o= will result in new files having the modes -rw——-, and new directories having the modes drwx——:

$ umask u=rwx,g=,o=
$ mkdir dir2
$ touch file2
$ ls -ld dir2 file2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值