Linux file Default Permissions calculation method Umask__linux

Source: Internet
Author: User

I recently watched "Uncle Bird's Linux private dish", because he is Taiwanese, so the way of expression and the mainland is not the same, the Taiwanese said the file is basically equal to what we say the document.

When you create a new file under Linux, you do not have to set permissions, you will have a default permission. This default permission is how to come out, is based on preset permissions and umask.

The default permissions for a file are-rw-rw-rw-, which is 666 points, and the default permissions for the directory are drwxrwxrwx, which is 777, and what is umask. Umask is the thing that calculates default permissions with preset permissions.

Direct input Umask can query your operating system umask value, the default is generally 0022, mainly to see the three digits, 022,w score is 2, which means that the file's default permissions are-rwr--r--(644)

Visible is the corresponding preset permissions to remove the W permission, because the owner of the use of the number is 0, so the permissions unchanged.

Similarly, the default permissions for the directory are also preset permissions to remove 022, i.e. drwxr-xr-x (755)

To this, the default permissions for files and directories come out. This umask can be set according to your needs. The orders are simple, like umask 0003.

It should be noted that do not reduce the number of preset permissions on the umask corresponding numbers, so that the calculated results are not necessarily true. For example, the preset permission score for a file is 666, minus 003, and becoming 663 is-rw-rw--wx

Both the owner and the group have no permissions to execute, but others have ... So the calculation is wrong. Minus the permissions, not the numbers. This should be remembered. 003, is to remove the W and x permissions.

So the correct result should be-rw-rw-r---in fact, the effect of 0003 and 0002 here is the same. 002 This umask is more suitable for a small working group to work together on a project, the team members of the project's files have permission to modify.


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.