linux下创建文件与目录时默认被赋予了什么样的权限?

时间:2023-01-25 05:41:15

当我们创建一个新的文件或目录的时候,他的默认权限是什么?

umask--指定当前使用者在创建文件或目录的时候默认的权限值

 [root@iZ288fgkcpkZ default]# umask 

 [root@iZ288fgkcpkZ default]# umask -S
u=rwx,g=rx,o=rx

r为4,w为2,x为1

以上为查看默认权限的两种方式,

第一种方式中的后三位是关于权限的,他的意思是:

当创建文件或目录的时候要拿掉的权限,022表示user,没有拿掉任何权限,group拿掉了写(2)权限,other则是拿掉了写(2)权限

第二种方式则更容易读懂,他的意思其实就是:

当创建文件或目录的时候,会被赋予的权限

值得注意的是,虽然 umask 显示说明是有执行权限的,那只是在创建文件夹的时候,当我们创建文件的时候是不会赋予执行权限的

如何修改默认权限?

 [root@iZ288fgkcpkZ hello]# umask 

 [root@iZ288fgkcpkZ hello]# umask -S
u=rwx,g=rx,o=rx
[root@iZ288fgkcpkZ hello]# umask
[root@iZ288fgkcpkZ hello]# umask [root@iZ288fgkcpkZ hello]# umask -S
u=rwx,g=rwx,o=r
[root@iZ288fgkcpkZ hello]# touch .txt
[root@iZ288fgkcpkZ hello]# ls -Al
总用量
-rw-r--r-- root root 7月 : .txt
-rw-rw-r-- root root 7月 : .txt
[root@iZ288fgkcpkZ hello]#

umask 003 意思是拿掉 other 的写(2)和执行(1)权限(当然是只保留了读权限), user 和 group 不拿掉任何权限

root 的 umask 会拿掉比较多的属性,root 的 umask 默认是 022

普通用户的 umask 为 002

linux权限对于文件和目录的重要性