umask 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 valueThe 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 nnnwhere 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 Permissionsumask file directory0 6 71 6 62 4 53 4 44 2 35 2 26 0 17 0 0For 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-------w3) directory Permissions rwx rwx r-x (775) This is the directory creation default permissions4) file Permissions rw-rw-r--(664) This is the file creation default permissionHere 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 permissions4) file Permissions rw-r--r--(644) This is the file creation default permissionC Common umask valuesThe following table lists some of the umask values and their corresponding directory and file permissions. common umask values and corresponding file and directory permissionsumask Value Catalog file0 7 5 5 6 4 40 7 5 0 6 4 00 7 7 5 6 6 40 7 7 1 6 6 00 7 7 0 6 6 0D umask CommandIf you want to know the current umask value, you can use the umask command:$umaskIf you want to change the umask value, simply set a new value using the umask command:$ umask 002confirm that the system has accepted the new U m a S K value:$umask002$touch testfile$ls-L testfilerw-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 createdthe default permission for the record is 0 6 6!
This article is from the "11862607" blog, please be sure to keep this source http://11872607.blog.51cto.com/11862607/1851292
Umask How to use