Previous Table of Contents Next

Module 147


The internal umask command masks your normal file modes, basically allowing you to have a personally defined set of modes for all new files and directories you create. By using umask you can:

*  Set the modes to be used on all new files and directories created.
*  Display the current masking for modes.

The normal default for a system is 022. This masks the write permission for the group users and all other users. The result of umask 022 on a new file is permissions of 755, which is displayed by ls -l as:

     -rwxr-xr-x 1  mylogin    ts        5 Jan 24 17:09 anewfile


Following is the general format of the umask command.

     umask [ nnn ]


The following argument may be passed to the umask command.

nnn The umask value is set to nnn. This value must be an octal number. It is subtracted from the standard mode of 777 column-by-column to define your new file creation mode. You may think of the umask as the modes being denied.
If you do not specify a value, the current umask value is displayed.


The chmod command is used to change modes and define the available absolute modes that can be used with umask. Refer to Module 17.


The umask command is usually used in the system's profile file or the user's own .profile. It provides a means of controlling what modes are set for all users as defaults. You may decide you want different default modes than are being used as a system default. If this is the situation, place a umask command in your .profile to set your umask each time you log in.


In this activity you use the umask command to set your default creation mode to 750. Begin at the shell prompt.

1.  First set your umask to all zeros by typing umask 000 and pressing Return.
2.  Create a file newfile1 by typing touch newfile1 and pressing Return.
3.  Type ls -l newfile1 and press Return to list the permissions of the file.
    cj> ls -l newfile1
    -rw-rw-rw-  1 mylogin     ts      0 Jan 25 13:42 newfile1

Note that the permissions are set to 666 (rw-rw-rw-) even though you had your umask set to 000. Thus the system masks off permissions of 111, your system's default mask may differ.
4.  Type umask 027 and press Return. Now all new files you create will have the mode of 640 which is 777 - 111 = 666 - 027 = 640.
5.  Type touch newfile and press Return to create a new file.
6.  Type ls -l newfile and press Return to list the new file's permissions. Notice the permissions; they will look like the following display:
    cj> ls -l newfile
    -rw-r-----  1  mylogin    ts       0 Jan 24 17:20 newfile
7.  Type rm newfile* and press Return to remove the two new files just created.
8.  Turn to Module 32 to continue the learning sequence.

Previous Table of Contents Next