| Home Profile Fun |
#120 Linux 03.06.2007
Control permissions of new files and directories with umaskIf a new file or directory is created it gets permissions defined by umask. Umask is set globally in /etc/profile and can be set for individual users in $HOME/.bash_profile. A typical example: umask 022 There is only one value for umask, which controls the permissions of new files and directories at the same time. If you change the value then the permissions for new files and new directories will change. But the behaviour is different for files and directories. The numbers 666 and 777 are used to calculate the permissions. To get the wright value for umask substract the permissions you want from these values: For example if you want files to be created with 644, then substract 644 from 666 which is 022. Then 022 is the value for umask. For directories 777 is used to calculate the permissions: To give new directories the permissions 755, substract 755 from 777 which results in 022 for the umask value. Conversely, to calculate the file and directory permissions from an umask value, substract it from 666 or 777. For example: umask 077. File permissions: 666 - 077 = 600, directory permissions: 777 - 077 = 700. |