linux默认文件权限是多少,Linux文件默认权限和umask笔记

94057f9962e238b0357baf7e81d09453.png

关于Linux文件默认权限的问题,可以实际先尝试一下如下命令:

root用户登录

[root@localhost test]# touch file1

[root@localhost test]# ls-l file1

-rw-r--r-- 1 root root 0 May 5 08:28 file1 #输出结果 对应的数字权限 644

[root@localhost test]# touch file2

[root@localhost test]# ls-l file2

-rw-r--r-- 1 root root 0 May 5 08:29 file2 #输出结果 对应的数字权限 644

[root@localhost test]# mkdir dir1

[root@localhost test]# ls-ld dir1

drwxr-xr-x 2 root root 4096 May 5 08:29 dir1 #输出结果 对应的数字权限 755

[root@localhost test]# mkdir dir2

[root@localhost tmp]# ls-ld dir2

drwxr-xr-x 2 root root 4096 May 5 08:29 dir2 #输出结果 对应的数字权限 755

user1用户登录

[user1@localhost test]# touch file1

[user1@localhost test]# ls-l file1

-rw-rw-r-- 1 root root 0 May 5 08:28 file1 #输出结果 对应的数字权限 664

[user1@localhost test]# touch file2

[user1@localhost test]# ls-l file2

-rw-rw-r-- 1 root root 0 May 5 08:29 file2 #输出结果 对应的数字权限 664

[user1@localhost test]# mkdir dir1

[user1@localhost test]# ls-ld dir1

drwxrwxr-x 2 root root 4096 May 5 08:29 dir1 #输出结果 对应的数字权限 775

[user1@localhost test]# mkdir dir2

[user1@localhost tmp]# ls-ld dir2

drwxrwxr-x 2 root root 4096 May 5 08:29 dir2 #输出结果 对应的数字权限 775

通过上面的执行结果可以得出以下结论:如果是root用户创建的文件默认权限是644,目录默认权限是755;普通用户创建的文件默认权限是664,目录默认权限是775.两者的默认权限是不同的,造成两者用户权限不同的原因就是Linux针对不同的用户创建文件和创建目录默认的权限不同,Linux系统通过umask(遮罩)的概念来控制相应的权限。可以在/etc/profile 文件中进行查看。

内容如下(51-55行):

if [ $UID-gt 99 ] && [ "`id-gn`" = "`id-un`" ]; then

umask 002

else

umask 022

fi

通过上面的文件内容可以看出:如果UID>99 设置的umask值为002,如果UID不大于99则umask值为022.关于遮罩计算权限的方式如下:比如 777 用字符串表示 rxwrwxrwx,如果遮罩值是022 对于的字符串是 ----w--w-,计算方法是如果遮着包含字母的,计算出真正的权限就不包含该位置的字母用-代替即可,个人理解公式:遮罩值+计算的真正权限=rxwrwxrwx上面的权限可以这样理解: ----w--w-+rxwr-xr-x=rxwrwxrwx

举报/反馈

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值