umask is subtractive, not prescriptive: permission bits set in umask are removed by default from modes specified by programs, but umask can't add permission bits. Show The mode of a file or directory is usually specified by the program which creates it; most system calls involved take a mode (e.g.
POSIX specifies that the default mode should be 666 for files, 777 for directories; but this is just a documentation default (i.e., when reading POSIX, if a program or function doesn't specify a file or directory's mode, the default applies), and it's not enforced by the system. Generally speaking this means that POSIX-compliant tools specify mode 666 when creating a file, and mode 777 when creating a directory, and the umask is subtracted from that; but the system can't enforce this, because there are many legitimate reasons to use other modes and/or ignore umask:
So you should think of umask as specifying the permission bits you don't want to see set by default, but be aware that this is just a request. You can't use it to specify permission bits you want to see set, only those you want to see unset.
Furthermore, any process can change its umask anyway, using the (For the sake of completeness, I'll mention that the behaviour regarding When you create a file or directory, the default file permissions assigned to the file or directory are controlled by the user mask. The user mask is set by the umask command in a user initialization file. You can display the current value of the user mask by typing umask and pressing Return. The user mask contains the following octal values:
Note that if the first digit is zero, it is not displayed. For example, if umask is set to 022, 22 is displayed. To determine the umask value you want to set, subtract the value of the permissions you want from 666 (for a file) or 777 (for a directory). The remainder is the value to use with the umask command. For example, suppose you want to change the default mode for files to 644 (rw-r--r--). The difference between 666 and 644 is 022, which is the value you would use as an argument to the umask command. You can also determine the umask value you want to set by using the following table, which shows the file and directory permissions that are created for each of the octal values of umask. Table 4–22 Permissions for umask Values
The following line in a user initialization file sets the default file permissions to rw-rw-rw-. Which of the following you must settings does not allow execute permission to be set by default on directory files?Which command is used to move all files to the bin sub-directory of the parent directory?
...
. What umask 0002?A umask of 002 is good when you share data with other users in the same group. Members of your group can create and modify data files; those outside your group can read data file, but cannot modify it. Set your umask to 007 to completely exclude users who are not group members.
What is default umask?By default, the system sets the permissions on a text file to 666, which grants read and write permission to user, group, and others, and to 777 on a directory or executable file. The value assigned by the umask command is subtracted from the default.
What will be permission of newly created file if umask is 002?This is telling us the So if we create a new file, it has the default permissions 664, which is 666 (the default permissions for files) masked by 002 (our umask value). As expected, the new file has permissions -rw-rw-r--, or 0664: The owner and group may read or write the file, and others may only read it.
What does chmod t do?The sticky bit can be set using the chmod command and can be set using its octal mode 1000 or by its symbol t (s is already used by the setuid bit). For example, to add the bit on the directory /usr/local/tmp , one would type chmod +t /usr/local/tmp .
|