< Day Day Up > |
Recipe 9.8. Setting Permissions Defaults with umask9.8.1 ProblemYou want to understand why files are created with a certain set of default permissions, and how to configure them yourself. 9.8.2 SolutionThe umask (user file-creation mode mask) controls this behavior. To see what yours is, use: $ umask
0022 or: $ umask -S
u=rwx,g=rx,o=rx To change it temporarily, for the duration of your login session, use: $ umask 0002 You can set the umask permanently by inserting the line umask 0022 or whatever value you want in your ~/.bashrc file. Table 9-3 shows common umask values.
9.8.3 DiscussionTable 9-4 shows that you can come up with a umask for any occasion.
umasks "subtract" permissions—though I warn you, do not say this to a programmer, because you will be subjected to a tedious lecture on how it's not subtraction, it's that "the umask is bitwise and-ed to whatever modes are specified when the file is created." However, I do not have a problem with calling it subtraction. When a program, such as a text editor or a compiler, creates a file, it is hardcoded to set the file permissions at either 0666 or 0777. If it knows the file it is creating is executable, it sets the permissions to 0777. The most common value is 0666, which is why you have to chmod +x scripts. Neither 0666 nor 0777 are appropriate permissions most of the time, so umask screens out the bits you don't want. For example, a umask of 0002 means regular files will become 0664, and executable files will become 0775. 9.8.4 See Also
|
< Day Day Up > |