Think of files as having a default permissions value of 666, and of directories as having a default permissions value of 777. When it comes to files, only program binaries and scripts need to have the executable permission. Directories, though, require that the executable permission be set if you want for people to be able to browse through them. So, there’s a lot better chance that you’ll want to create directories with executable permissions.
A umask is a way of setting a default permissions value for any files or directories that you create on your system. When you set a umask, you’re telling the system what permissions to remove from the normal default setting. You’ll see the umask represented by either a three or four digit value.
There is one slight caveat to using umask. When you set the umask on your system, it doesn’t affect the permissions settings for any files or directories that are already there. If you need the permissions settings changed for any pre-existing files or directories, you’ll have to do that yourself after you’ve changed the umask.
There are several ways to change the umask on your system.
If you want to change the global umask setting, then you can edit the /etc/bashrc file. When you open this file, you should see an “if–else” loop that sets the umask to “002″ for normal users, and to “022″ for the root user. So, for example, if you want to change the global umask setting for normal users to “077″ just change the “002″ to “077″.
To verify what your umask is, just open a command-line terminal and enter “umask”. You should see a four-digit value such as “0002″. This is really saying that your system’s umask is 002; the extra 0 at the beginning just means that the number is in octal format. You can also use the umask command to temporarily set a umask. Just enter “umask”, followed by the value of the desired umask setting. For example:
Note though, that this will only last for the length of your log-in session.
If an individual user wants to make a permanent change to his or her own customized umask, all that’s necessary is to edit the “.bashrc” file in the users’s home directory. They’ll just need to add a line such as:
Here you can see two files created, the first created with the system umas 002 and the second one created after setting the umask to 077.
-rw-rw-r-- 1 joe joe 5 Aug 7 00:25 new
-rw------- 1 joe joe 5 Aug 7 00:26 new2