In Unix, how do I set the default protection to newly created directories and files?

The umask command, when placed in the .cshrc file (for the csh and tcsh shells), the .profile file (for the Korn shell), or the .bash_profile file (for the bash shell), acts as a umask that screens out permissions automatically each time you create a new directory or file in your account. If a directory is readable, writable, and executable by the owner, a selected group of users, and everyone on the system, its octal permission is 777. If a file is readable and writable by the owner, a selected group of users, and everyone on the system, its octal permission is 666. The umask command is followed with a number that is subtracted from 777 on directories, and from 666 on files. The result gives the default protection for new directories and files.

Note:
You can use the chmod command to set permissions for existing files and directories. For more information about using the chmod command, see In Unix, how do I change the permissions for a file?

Place the following line in a .cshrc, .profile, or .bash_profile, or to set the default permissions for directories and files in your account:

 umask 022

Using this line, all new directories created in your account are given a default protection of 755 (i.e., 777 - 022), which grants read, write, and execute permission to the owner of the directory, and read and execute permission to the group and others. New files created in your account are given a default protection of 644 (i.e., 666 - 022), which grants read and write permission to the owner of the file, and read permission to the group and others.

Octal number Permission
400 Read by owner
200 Write by owner
100 Execute by owner
040 Read by group
020 Write by group
010 Execute by group
004 Read by others
002 Write by others
001 Execute by others

By default, most shells set the umask to 022, giving you write and read permissions, and others read permissions on new directories and files. To determine what the current umask setting is, at the Unix prompt, enter:

 umask

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document acge in the Knowledge Base.
Last modified on 2017-05-16 11:49:48.

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.