Set umask in Linux and umask in linux

Source: Internet
Author: User

Set umask in Linux and umask in linux

In linux, you often need to prompt settings:
Umask 022

Its functions are as follows:

Function Description: Specifies the default permission mask when creating a file.
Syntax: umask [-S] [permission mask]
Note: umask can be used to set the [permission mask]. The [permission mask] is composed of three Octal numbers. After the existing access permissions are removed from the permission mask, the preset permissions for file creation can be generated.
Parameters:
-S indicates the permission mask in text format.
File: uses the octal base 666, that is, no x-bit (executable bit) rw-. The execution bit must be added by the user.

Example 1: If the file to be generated appears with the permission word rw-r --, that is, the actual permission is expressed as 644 in octal mode, and the base number is reduced by 666, that is, the mask. Use umask 022.

Note: The effect of 033 is the same as that of 022. If the 033 mask is used for setting, the actual permission should be 633, that is, rw-r-x, but the premise is that the file does not generate x-bit, therefore, the File Permission will eventually appear as rw-r.

Directory: uses the octal base 777

Example 2: Set the directory permission to be generated to the permission field rwxr-xr-x, that is, the actual permission is expressed as 755 in octal, the mask 022 is obtained after the accesskey word is subtracted from the base 777. Umask 022 is used for setting.

Summary:

Master two key points: 1. The file base is 666, And the directory is 777. That is, the file does not have x bits, and the directory can be set to x bits. 2. If chmod is set to which bit, which bit has the permission, and umask is set to which bit, then no permission is granted to which bit.

Instance:

# Umask
00

# Mkdir test
# Ls-ltr
Drwxrwxrwx 2 root sys 96 Oct 11 :10 test
# Umask 022
# Umask
022
# Mkdir test2
# Ls-ltr
Drwxrwxrwx 2 root sys 96 Oct 11 :10 test
Drwxr-xr-x 2 root sys 96 Oct 11 :11 test2

Vernacular:

In fact, the default permissions are different. umask is used to set the default permissions.

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.