Umask in Linux

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.