What does `umask` control in file creation?

umask (user file creation mask) controls the default permissions assigned to newly created files and directories in a Unix-like operating system. It specifies which permission bits should be turned off (masked) when a file or directory is created.

The default permissions for files are typically 666 (read and write for owner, group, and others) and for directories, it's 777 (read, write, and execute for owner, group, and others). The umask value is subtracted from these defaults to determine the final permissions.

For example:

  • If the umask is set to 022, the permissions for new files will be 644 (read and write for the owner, read for group and others) and for new directories, it will be 755 (read, write, and execute for the owner, read and execute for group and others).

You can check the current umask value by running the command:

umask

To set a new umask, you can use:

umask 027

This would set the umask to 027, resulting in new files having 640 permissions and new directories having 750 permissions.

0 Comments

no data
Be the first to share your comment!