1. Default permissions for files and directories
In Linux, when we create a file or directory, we do not specify the permissions of the three categories of user,group,other, in fact the umask (matte code) determines the default permissions at the time of creation. If it is a file, use 666-umask; if it is a directory, use 777-umask. Remember one of the rules of Linux: Files should not have executable permissions by default.
2. Experiments
Root User under:
[[email protected] ~]# Touch Zfz.file[[email protected] ~]# mkdir zfz.dir[[email protected] ~]# ls-l zfz.file-rw-r--r--1 Root root 0 May 09:42 Zfz.file[[email protected] ~]# ls-ld zfz.dirdrwxr-xr-x 2 root root 4096 * * 09:42 zfz.dir[[e Mail protected] ~]# Umask0022[[email protected] |
Under General users:
[[email protected] ~]$ Touch Hive.file[[email protected] ~]$ mkdir hive.dir[[email protected] ~]$ ls-l hive.file-rw-rw-r- -1 hive Hive 0 09:43 hive.file[[email protected] ~]$ ls-ld hive.dirdrwxrwxr-x 2 hive hive 4096 may 09:43 hive. Dir[[email protected] ~]$ umask0002 |
3. Thinking
If we set Umask to 023, create a file, 666-023=643=rw-r---wx, create a directory, 777-023=754=RWXR-XR--。 However, in fact, because the file can not have executable permissions by default, resulting in 643 must be added 1, that is, 644=rw-r--r--。 "Must not let the file default executable permissions, if the calculated permissions have X, then the overall plus 1"
Look at the following example:
[[email protected] ~]$ umask 555[[email protected] ~]$[[email protected] ~]$ Umask0555[[email protected] ~]$ touch hive2.f Ile[[email protected] ~]$ ls-l hive2.file--w--w--w-1 hive Hive 0 may + 10:05 hive2.file[[email protected] ~]$ |
This article is from the "I want to surpass myself" blog, please be sure to keep this source http://zhangfengzhe.blog.51cto.com/8855103/1413057