Linux Umask use detailed

Source: Internet
Author: User

transferred from: http://blog.csdn.net/lmh12506/article/details/7281910umask How to use

A What is Umask?

When we log into the system and create a file that always has a default permission, how does this permission come from? That's what Umask did. Umask set the user to create the default permissions of the file, it is the opposite of chmod effect, Umask set the right "complement", and chmod set the file permission code. You typically set the Umask value in/etc/profile, $ [Home]/.bash_profile, or $[home]/.profile.

Your system administrator must set a reasonable umask value for you to ensure that the file you create has the desired default permissions, preventing other non-identical users from having write access to your files. After you have logged in, you can use the umask command to change the default permissions for file creation according to your personal preferences. The corresponding change is valid until you exit the shell or use a different umask command. In general, the Umask command is set in the/etc/profile file, which is referenced by each user at login, so if you want to change the umask of all users, you can include the corresponding entry in the file. If you want to permanently set your own umask value, place it in a. Profile or. bash_profile file in your own $home directory.

B how to calculate the Umask value

The Umask command allows you to set the default mode for file creation, with a corresponding number of umask values for each type of user (file owner, same group of users, other user). For a file, the maximum value for this number is 6, respectively. The system does not allow you to give it permission to create a text file, and you must add this permission with the chmod command after creation. The directory allows you to set execution permissions, so that for the directory, the number of umask can be up to 7.

The general form of the command is:

Umask nnn

Where nnn is Umask 000-777.

Let's take a look at some examples.

Calculate your Umask value:

There are several ways to calculate umask values, and you can set the default permissions for newly created files and directories by setting the Umask value. The following table lists the umask values that correspond to the permission phase.

When calculating the Umask value, you can find the corresponding Umask value by creating the default permissions for each type of user in this table according to the desired file/directory.

For example, the default permissions for file and directory creation for the Umask value 002 are 6 6 4 and 7 7 5, respectively.

There is another way to calculate umask values. We just have to remember that Umask is "taking" the appropriate bits from the permission.

Umask Values and Permissions

Umask file Directory

0 6 7

1 6 6

2 4 5

3 4 4

4 2 3

5 2 2

6 0 1

7 0 0

For example, for the Umask value 0 0 2, what are the corresponding file and directory default creation permissions?

In the first step, we first write a pattern with full permissions, that is, 777 (all users have read, write, and Execute permissions).

In the second step, the following line writes the corresponding bit according to the Umask value, which in this case is 0 0 2.

The third step is to make a note in the next line that there are no matching bits in the above two lines. This is the default creation permission for the directory.

This method can be remembered with a little practice.

The fourth step, for the file, at the time of creation can not have execute permission, just take out the corresponding execution permission bit.

This is the example above, where the u m a S K value is 0 0 2:

1) Maximum file permissions rwx rwx rwx (777)

2) umask value is 0 0 2-------w

3) directory Permissions rwx rwx r-x (775) This is the directory creation default permissions

4) file Permissions rw-rw-r--(664) This is the file creation default permission

Here is another example, assuming that the u m a S K value is 0 2 2:

1) Maximum file permissions rwx rwx rwx (777)

2) u m a S K value is 0 2 2----w-w-

3) directory Permissions rwx r-x r-x (755) This is the directory creation default permissions

4) file Permissions rw-r--r--(644) This is the file creation default permission

C Common umask values

The following table lists some of the umask values and their corresponding directory and file permissions.

Common umask values and corresponding file and directory permissions

Umask Value Catalog file

0 22 7 5 5 6 4 4

0 27 7 5 0 6 4 0

0 02 7 7 5 6 6 4

0 06 7 7 1 6 6 0

0 07 7 7 0 6 6 0

D umask Command

If you want to know the current umask value, you can use the Umask command:

$umask

If you want to change the umask value, simply set a new value using the Umask command:

$ umask 002

Confirm that the system has accepted the new U m a s K value:

$umask

002

$touch testfile

$ls-L Testfile

rw-rw-r--

Be sure to figure out what kind of File/directory creation default permissions you want before using the Umask command. Otherwise, you may get some very strange results; For example, if you set the Umask value to 6 0 0, the file/target created

The default permission for the record is 0 6 6!

Linux Umask use detailed

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.