unmask Command in Linux

Learn via video courses
Topics Covered

Overview

In Linux, the umask command is used to set the default permissions for newly created files and directories. The default permissions are based on the value of the umask. Understanding how the umask command works is essential for managing file permissions in Linux.

Linux umask Command Syntax

The syntax for the umask command is as follows:

Where:

  • -S: Displays the current umask value in symbolic format.
  • mode: Specifies the new umask value. This can be either an octal value or a symbolic value.

umask Command Options:

  • -S: Displays the current umask value in symbolic format.

Example Usages

  • Display the current umask value in octal format.:

    Output:

    Explanation: The output 0022 means that newly created files will have permissions of 644 (-rw-r--r--) and newly created directories will have permissions of 755 (drwxr-xr-x).

  • Display the current umask value in symbolic format.:

    Output:

    Explanation: The output u=rwx,g=rx,o=rx means that newly created files will have permissions of 644 (-rw-r--r--) and newly created directories will have permissions of 755 (drwxr-xr-x).

  • Set the umask value to 077.:

    Explanation: This command sets the umask value to 077, which means that newly created files will have permissions of 600 (-rw-------) and newly created directories will have permissions of 700 (drwx------).

Tips

  • The umask value is subtracted from the maximum permission value (777 for files and 7777 for directories) to determine the default permission value for newly created files and directories.

  • The default umask value is usually set in the /etc/profile or /etc/bashrc file.

  • The umask value is inherited by child processes.

Advanced Use Cases of umask Command in Linux

  • Set the umask value for a specific user.:

    Explanation: This command adds the line 'umask 077' to the user's .bashrc file, which sets the umask value to 077 every time the user logs in.

  • Set the umask value for a specific process.:

    Explanation: This command sets the umask value to 022 for the duration of the 'command' process.

  • Use symbolic values to set the umask value.:

    Explanation: This command sets the umask value to u=rwx,g=,o=, which means that newly created files will have permissions of 600 (-rw-------) and newly created directories will have permissions of 700 (drwx------). The u=rwx specifies that the user has read, write, and execute permissions, the g= specifies that the group has no permissions, and the o= specifies that others have no permissions.

Conclusion

  • The umask command is used to set the default permissions for newly created files and directories in Linux.

  • The default permissions are based on the value of the umask, which is subtracted from the maximum permission value to determine the default permission value.

  • The umask value can be set using either an octal value or a symbolic value.

  • The umask value can be displayed in either octal or symbolic format.

  • The default umask value is usually set in the /etc/profile or /etc/bashrc file.

  • The umask value is inherited by child processes.