Linux umask command

The umask command in Linux is used to set the default file permissions for newly created files and directories. It helps define the permissions that are automatically applied when a file or directory is created.

Here’s an overview of how to use the umask command:

  1. Basic Usage:
    To set the default file permissions using umask, you can use the octal representation of the permission mask. The umask value is subtracted from the default permission value (usually 666 for files and 777 for directories) to determine the final permissions. For example:
   umask 022

This command sets the default file permissions to 644 (666 – 022) and default directory permissions to 755 (777 – 022).

  1. Displaying the Current Umask:
    To display the current umask value, simply type umask without any arguments. For example:
   umask

This command will display the current umask value in octal format.

  1. Examples:
  • Setting the umask value: umask 027 This command sets the default file permissions to 640 (666 – 027) and default directory permissions to 750 (777 – 027).
  • Displaying the current umask value:
    umask
    This command displays the current umask value in octal format, such as 0022 or 0007.

The umask command allows you to define the default file permissions for newly created files and directories. It is particularly useful for maintaining consistent permissions across your files and directories.

Note that the umask value is subtracted from the default permissions, so a higher umask value results in more restrictive permissions.

For more information about the umask command and its options, you can refer to the manual page by typing man umask in your terminal.