umask

>Usage

umask (User Mask or File Creation Mask) is a command used to set default permissions for newly created files and directories. By setting a umask, you can control what the default permissions will be, ensuring they are either more restrictive or more permissive based on your needs.

>Synopsis

umask [option] [option]

>Options

-No options

-No options (display): Displays the current umask value, which represents the default permissions mask.

Example 1:

Dots

-zsh

>umask


This value represents the permissions subtracted from the default

-Numeric value

-Numeric value (set mask): Sets a new default mask using a numeric value, where each digit controls different permission levels.
The first digit controls the owner's permissions (read, write, execute).
The second digit controls the group's permissions.
The third digit controls others' permissions.

Example 2:

Dots

-zsh

umask 027


Silent on success: No output after setting the new umask.

-S

-S (symbolic format): Sets the umask in symbolic format instead of numeric format. This option allows you to use letters (e.g., r, w, x) to represent permissions.

Example 3:

Dots

-zsh

> umask -S


u=rwx,g=rx,o=rx

-Default file permissions

-Default file permissions: By default, files are created with rw-r--r-- and directories with rwxr-xr-x. The umaskcommand modifies this behavior to set more restrictive or permissive permissions for new files.

Example 4:

Dots

-zsh

> umask 0777


Effect: New files will have rw-r--r-- (666 - 022 = 644), and new directories will have rwxr-xr-x (777 - 022 = 755).

-mask and directories

-mask and directories: When a directory is created, the umask subtracts the set value from the default directory permissions rwxrwxrwx (777), resulting in more restrictive permissions for new directories.

Example 5:

Dots

-zsh

> umask 0022


Default permissions will be rwxr-xr-x (777 - 022 = 755).

-mask and files

-mask and files: The umask also affects newly created files, where the default permissions are more restrictive (e.g., rw-r--r--).

Example 6:

Dots

-zsh

> umask 022


Default permissions will be rw-r--r-- (666 - 022 = 644).

-Setting umask for script files

-Setting umask for script files:You can set the umask to ensure script files have executable permissions by default.

Example 7:

Dots

-zsh

> umask 0077


ffect: New script files will have the most restrictive permissions (rw-------), meaning only the owner can read and write.

-Mask calculation

-Mask calculation: The umask command works by subtracting the umask value from the default value (666 for files and 777 for directories).

Example 8:

Dots

-zsh

> umask 0777


Removes all permissions for new files: 0 (no read, write, or execute permissions).

>Quiz

Progress: Question ? out of ?

Question Title

Page written by FIlippo Orlando