Recently just the system to learn the Linux file permissions this piece, in the "Umask value and its corresponding file permissions" on this issue, looked for video (old boy teacher's video, highly recommended), also looked at the bird Brother's book, of course, also found on the Internet, find that the calculation methods are various, But personally feel mastered a kind of good, see a variety of methods, actually most are looking for the law, not to find the law is too complex, so the personal feeling is not too good to remember, time a long may forget, so according to their own understanding, do various tests, found the following better methods. (better approach from the level of understanding and memory)
1. The problem arises: when you set Umask to 004 and 005, the default permissions are the same for the created file.
To set the Umask to 004:
[[email protected] right]# umask 005[[email protected] right]# Umask0005[[email protected] right]# Touch 005file[[email PR Otected] right]# ls-l 005file-rw-rw--w-1 root root 0 July 12:19 005file
Here the analysis, for the sake of simplicity, I am only concerned about the others permissions to analyze.
From the above output can be seen, others permissions for-w-, that is, 3, by the meaning of umask (to take off the right) know, take off 5, that is, the R and X permissions (by R W x corresponding to the number 4 2 1), so the creation of the 005file file others permissions is-w-, That's 2, which is not contrary to our perception.
To set the Umask to 004:
[[email protected] right]# umask 004[[email protected] right]# Umask0004[[email protected] right]# Touch 004file[[email PR Otected] right]# ls-l 004file total usage 0-rw-rw--w-1 root root 0 July 12:21 004file
According to the above analysis, as a matter of principle, here took off the others 4 is the right to R, then the new creation of the file others permissions should be-rx, but here is how-r-it? Did the system go wrong?
Of course not, here is also the most critical problem, as a conclusion:
For files, if Umask does not remove the X permission, the system automatically handles the X permission;
For the file, if the umask has removed the X permission, then the system according to normal conditions to remove the appropriate permissions;
For catalogs, there is no such situation.
What do you mean?
Take the two examples above:
(1) for setting Umask to 004, that is, to take off (others) R permissions, so the default permissions should be-WX, but because Umask did not remove the X permission, so when we create a new file, the system automatically helps us to take the X permission off, so, The permission to create the file is-w-.
(2) for setting Umask to 005, that is, to take off (others) R and X permissions, at this time, umask have to remove the X permission, so we will be treated as normal, that is, the permission to create the file is-r-
(3) So by the above analysis can be known, set Umask to 004 and 005, the file's default permissions are the same.
2. In-depth analysis: Why does the system automatically take out x permissions for us?
Think about it, we usually use touch to create files, the vast majority of what is used to do? Of course it is used to store and record data, so that such a file should not be able to execute (even with the permission of X), so in this case, when we create the file, it should not be necessary to add the X permission, if it is necessary, you manually to a file plus x permissions ok.
So for this reason, the system will help us automatically take out the X permission.
3. Recommendation: To absorb the "umask value and its corresponding file permissions" knowledge in an understanding way
The above (2nd) is not a scientific basis, but I personally based on the results of the actual test to make a guess, of course, Brother Bird's book also seems to be revealing this point (just feel not clear and clear).
I myself as a novice Linux, is currently working hard to see the teacher's video, but also watching Bird Brother's book, personally think that memory is better, such as Umask is 006, because 6 means to take the R and W permissions removed, but did not take the X permission, so when we create the file, The system will take this X permission also removed, the final ohters of the authority is---, and then for example, Umask for 3, because 3 means to take the W and x permissions, including x permission, in order to create the file, the final ohters permissions will be r--.
I think for most people, such a method to calculate the answer should be relatively fast, at least I think I am not clever, but also can be relatively fast mental arithmetic out, of course, if you want to know: 1.umask is the meaning of 2.R W x corresponds to the number of 4 2 1 (in fact, the binary one, 二、三位, is 2 0 times, 1 times, 2 times Square), compared to memory odd or even, I think this method for the novice should be more able to understand and memory.
Of course, the above is only a personal point of view, but as a novice, it is recommended to use such a method to understand and remember.
This article is from the "fragrant fluttering leaves" blog, please make sure to keep this source http://xpleaf.blog.51cto.com/9315560/1679861
Talking about the Umask value and its corresponding file permission in Linux