UMASK(1P)

๐Ÿ‘‘ UMASK(1P) โ€” the POSIX Programmer's Manual page, but make it make sense ๐Ÿ’…

okay bestie, sit down, hydrate, and let's talk about umask from the POSIX Programmer's Manual. It's giving "tiny command, huge consequences," fr fr. โœจ


๐Ÿšจ PROLOG ๐Ÿšจ

This manual page is part of the POSIX Programmer's Manual. Heads up though: the Linux implementation of this interface may differ โ€” so if you're on Linux, go consult the corresponding Linux manual page for the deets on Linux behavior. Or the interface might just... not be implemented on Linux at all. ๐Ÿ™ˆ No cap.


๐Ÿ’– NAME ๐Ÿ’–

umask โ€” get or set the file mode creation mask. That's the whole vibe. She's simple. She's powerful. She's your new bestie. ๐Ÿซถ


โœจ SYNOPSIS โœจ

umask [-S] [mask]

That's it. Two little pieces and she can rearrange your entire permission situation. iconic.


๐ŸŒธ DESCRIPTION ๐ŸŒธ

okay so here's the tea. The umask utility shall set the file mode creation mask of the current shell execution environment (peep Section 2.12, Shell Execution Environment) to whatever value you gave it in the mask operand. ๐ŸŽ€

This mask affects the initial value of the file permission bits of files you create afterwards. So like, everything you make after this? Yeah. Masked. ๐Ÿ’…

Here's the important part though โ€” if umask gets called in a subshell or a separate utility execution environment, like one of these:

(umask 002)
nohup umask ...
find . -exec umask ... \;

then it shall not affect the file mode creation mask of the caller's environment. So you can't sneak-changes into your parent shell from inside a subshell, bestie. Not happening. ๐Ÿ’€

And if you don't specify the mask operand? Then umask shall write the value of the file mode creation mask of the invoking process to standard output. Just reads it back to you like a lil mirror. ๐Ÿชž


๐ŸŽ€ OPTIONS ๐ŸŽ€

The umask utility shall conform to the Base Definitions volume of POSIX.1โ€2017, Section 12.2, Utility Syntax Guidelines. (We love a girl who follows the rules. ๐Ÿ’–)

The following option shall be supported:

  • -S โ€” Produce symbolic output. That's it, that's the flag. ๐ŸŒˆ

Also important: the default output style is unspecified, but it shall be recognized on a subsequent invocation of umask on the same system as a mask operand, so you can restore the previous file mode creation mask. So like, the default format is a mystery but she always knows how to read her own handwriting. ๐Ÿ”ฅ


๐Ÿฆ‹ OPERANDS ๐Ÿฆ‹

The following operand shall be supported:

  • mask โ€” A string specifying the new file mode creation mask. The string is treated in the exact same way as the mode operand described in the EXTENDED DESCRIPTION section for chmod. (Yes, you have to go read chmod too. Sorry babe, cross-referencing is the tax. ๐Ÿ˜ญ)

Let's break the mask rules all the way down, no skips:

  • For a symbolic_mode value, the new value of the file mode creation mask shall be the logical complement of the file permission bits portion of the file mode specified by the symbolic_mode string. Yes, complement. Opposite girl. She's contrarian on purpose. ๐Ÿ’…
  • In a symbolic_mode value, the permissions op characters '+' and '-' shall be interpreted relative to the current file mode creation mask:
    • '+' shall cause the bits for the indicated permissions to be cleared in the mask.
    • '-' shall cause the bits for the indicated permissions to be set in the mask.
    • (Yes, it's backwards from what you'd expect. That's the mask logic, bestie, it's just built different. ๐Ÿ™ˆ)
  • The interpretation of mode values that specify file mode bits other than the file permission bits is unspecified. So don't come crying when it does something weird. ๐Ÿ‘€
  • In the octal integer form of mode, the specified bits are set in the file mode creation mask.
  • The file mode creation mask shall be set to the resulting numeric value.
  • The default output of a prior invocation of umask on the same system with no operand also shall be recognized as a mask operand. So she speaks her own language and understands it. ๐Ÿ’œ

๐Ÿ’€ STDIN ๐Ÿ’€

Not used. She doesn't want your input here. ๐Ÿ™…โ™€๏ธ


๐Ÿ“ INPUT FILES ๐Ÿ“

None. Nothing. Zero files. Empty. ๐Ÿ“


๐ŸŒˆ ENVIRONMENT VARIABLES ๐ŸŒˆ

The following environment variables shall affect the execution of umask:

  • LANG โ€” Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1โ€2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
  • LC_ALL โ€” If set to a non-empty string value, override the values of all the other internationalization variables. She's the main character, she overrides everybody. ๐Ÿ‘‘
  • LC_CTYPE โ€” Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments).
  • LC_MESSAGES โ€” Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
  • NLSPATH โ€” Determine the location of message catalogs for the processing of LC_MESSAGES.

โšก ASYNCHRONOUS EVENTS โšก

Default. Nothing special, nothing dramatic. ๐Ÿ˜Œ


๐ŸŒŸ STDOUT ๐ŸŒŸ

When the mask operand is not specified, the umask utility shall write a message to standard output that can later be used as a umask mask operand. Round trip. Slay. โœจ

If -S is specified, the message shall be in the following format:

"u=%s,g=%s,o=%s\n", <owner permissions>, <group permissions>,
    <other permissions>

where those three values shall be combinations of letters from the set {r, w, x}. And listen โ€” the presence of a letter shall indicate that the corresponding bit is clear in the file mode creation mask. Yes, presence means clear. I know. Mask logic. It's giving chaos but it's the standard. ๐Ÿ’…

If a mask operand is specified, there shall be no output written to standard output. Silence. ๐Ÿคซ


๐Ÿ˜ญ STDERR ๐Ÿ˜ญ

The standard error shall be used only for diagnostic messages. That's her only job here. Don't ask her for more. ๐Ÿ™ˆ


๐Ÿ“‚ OUTPUT FILES ๐Ÿ“‚

None. Again. Nothing. ๐Ÿ“


๐Ÿงš EXTENDED DESCRIPTION ๐Ÿงš

None. This section is literally just vibes and empty space. Moving on. ๐Ÿ’œ


โœ… EXIT STATUS โœ…

The following exit values shall be returned:

  • 0 โ€” The file mode creation mask was successfully changed, or no mask operand was supplied. Either way, we win. ๐ŸŽ‰
  • >0 โ€” An error occurred. Something went sideways, bestie. ๐Ÿ˜ญ

๐ŸŒ€ CONSEQUENCES OF ERRORS ๐ŸŒ€

Default.

And jsyk: the following sections are informative. So everything from here down is like... helpful context, not the hard requirement. Still read it though. ๐Ÿ’–


๐Ÿ’… APPLICATION USAGE ๐Ÿ’…

Since umask affects the current shell execution environment, it is generally provided as a shell regular built-in. So like, she lives inside your shell. She's not some outside contractor. ๐Ÿ 

And here's the big-brain bit: in contrast to the negative permission logic provided by the file mode creation mask and the octal number form of the mask argument, the symbolic form of the mask argument specifies those permissions that are left alone. So octal tells her what to mask, symbolic tells her what to leave. Two completely different energies. No cap. ๐Ÿง โœจ


๐Ÿ”ฅ EXAMPLES ๐Ÿ”ฅ

okay bestie, examples time. Either of these commands:

umask a=rx,ug+w

umask 002

sets the mode mask so that subsequently created files have their S_IWOTH bit cleared. ๐Ÿ’…

After setting the mode mask with either of the above commands, the umask command can be used to write out the current value of the mode mask:

$ umask
0002

(Quick note: the output format is unspecified, but historical implementations use the octal integer mode format. So don't @ her if yours looks different. ๐Ÿ™ˆ)

$ umask -S
u=rwx,g=rwx,o=rx

Either of these outputs can be used as the mask operand to a subsequent invocation of the umask utility. See? Round trip. Told you. ๐Ÿ”

Assuming the mode mask is set as above, the command:

umask g-w

sets the mode mask so that subsequently created files have their S_IWGRP and S_IWOTH bits cleared. Two birds, one command. ๐Ÿฆ‹

And the command:

umask -- -w

sets the mode mask so that subsequently created files have all their write bits cleared.

โš ๏ธ Careful bestie: note that mask operands -r, -w, -x or anything beginning with a <hyphen-minus> must be preceded by -- to keep it from being interpreted as an option. Otherwise she'll think you're passing a flag and it's gonna get messy. ๐Ÿ’€

๐Ÿง  RATIONALE ๐Ÿง 

Since umask affects the current shell execution environment, it is generally provided as a shell regular built-in. And if it is called in a subshell or separate utility execution environment, like one of these:

(umask 002)
nohup umask ...
find . -exec umask ... \;

then it does not affect the file mode creation mask of the environment of the caller. Same energy as before, just restated in the rationale section. ๐Ÿ’–

The description of the historical utility was modified to allow it to use the symbolic modes of chmod. And the -s option used in early proposals was changed to -S because -s could be confused with a symbolic_mode form of mask referring to the S_ISUID and S_ISGID bits. So like, they had to rename her because the lowercase version was causing confusion. glowed up to capital. ๐Ÿ’…

The default output style is unspecified to permit implementors to provide migration to the new symbolic style at the time most appropriate to their users. And a -o flag to force octal mode output was omitted because the octal mode may not be sufficient to specify all of the information that may be present in the file mode creation mask when more secure file access permission checks are implemented. So no -o. Never was. Don't go looking. ๐Ÿ™ˆ

And here's a lil history tea: it has been suggested that trusted systems developers might appreciate ameliorating the requirement that the mode mask โ€œaffectsโ€ the file access permissions, since it seems access control lists might replace the mode mask to some degree. So the wording has been changed to say that it affects the file permission bits, and it leaves the details of the behavior of how they affect the file access permissions to the description in the System Interfaces volume of POSIX.1โ€2017. The vibes were adjusted. The standard remains the standard. ๐Ÿ‘‘


๐Ÿ”ฎ FUTURE DIRECTIONS ๐Ÿ”ฎ

None. She's not planning any glow-ups. She's perfect as she is. ๐Ÿ˜Œ


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

  • Chapter 2, Shell Command Language, chmod
  • The Base Definitions volume of POSIX.1โ€2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
  • The System Interfaces volume of POSIX.1โ€2017, umask()

go read those too, bestie. iykyk. ๐Ÿ“š๐Ÿ’–


Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie!! ๐Ÿ’– this was brought to you by IEEE/The Open Group, dated 2017, and it's the UMASK(1P) page from the POSIX Programmer's Manual. stay masked, stay iconic, and remember: -- before your hyphen-minus masks or she'll eat your flags. mwah ๐Ÿ’…โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from