ArticleslgStudy

science

Umask

Umask is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Umask rather than just read about it. In short: umask is a shell command that reports or sets the mask value that limits the file permissions for newly created files in many Unix and Unix-like file systems. A system call with the same name, umask(), provides access to the mask value stored in the operating system (OS), and the command provides shell user access to the system call.

Key takeaways

  • Umask belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Umask to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Umask from memory before moving on to harder problems.

Reference excerpt

umask is a shell command that reports or sets the mask value that limits the file permissions for newly created files in many Unix and Unix-like file systems. A system call with the same name, umask(), provides access to the mask value stored in the operating system (OS), and the command provides shell user access to the system call. Additionally, the mask value, formally file mode creation mask, is often referred to as the umask. When a new file is created, its access permissions are restricted by the stored umask mask value. The file's permission bits that each grant access are cleared by corresponding bits of the mask that are set. Set bits of the mask disallow the permission and clear bits of the mask allow the permission. The otherwise default value of a file's permissions is defined elsewhere. The mask just prevents corresponding bits of the default. The mask acts as a last-stage filter that strips away permissions as a file is created; each bit that is set strips away its corresponding permission. Permissions may be changed later including via the chmod command. The operating system maintains a umask mask value for each process that is accessible via the umask command and umask() system call. When a process spawns a new process, the child inherits the mask from its parent. Generally, the mask only affects file permissions during the creation of new files; however, the chmod command checks the mask when the mode options are specified using symbolic mode and a reference to a class of users is not specified. The umask command is used with Unix-like operating systems, and the umask() system call is defined in the POSIX.1 specification.

History Before the umask capability (command, system call and stored value) was introduced to Unix, developers used various mechanisms to restrict access in order to prevent security breach. The umask capability was introduced around 1978, in the seventh edition of the operating system, to allow sites, groups and individuals to choose their own defaults. The capability has been implemented in most, if not all, contemporary Unix-like operating systems.

Shell command

Read With no parameter, the umask command reports the stored mask either as octal or symbolic notation, depending on the implementation. In some shells, the -S option selects symbolic notation. For example:

Set as octal Invoked with an octal parameter, the command updates the stored mask to input value:

As normal for a numeric representation, if fewer than 4 digits are entered, leading zeros are assumed. But the command fails if the input is more than 4 digits. This is notable since some languages (i.e. C) use a leading zero to denote octal format for a literal, but umask does support this notation. The last three digits encode the user, group and others classes, respectively. If a fourth digit is present, the first digit addresses the three special attributes: setuid, setgid and sticky bit.

Set via symbolic notation When umask is invoked with a parameter in symbolic notation, it modifies the stored mask so that a newly created file is allowed to have the permissions added and disallowed to have the permissions removed. The logic is backwards from the mask value. Adding a permission clears the associated bit of the mask so that the permission is allowed when a file is created. Removing a permission sets the associated bit so that the permission is disallowed when a file is created. Changes to the mask in symbolic notation are expressed as [classes]+|-|=operations; with multiple expressions separated by comma and the last terminated by a space. This syntax does not work in C shell due to the different behavior of its umask command. Class is specified as u for user, g for group, o for others or a combination of these letters to select multiple. If not specified or a, then all classes are selected, same as ugo. The operator specifies how the mask is modified. + allows the specified permissions without changing unspecified permissions. - disallows permissions without changing unspecified permissions. = allows the specified permissions and disallows the unspecified permissions of the class. The following table describes the operations (and flags) than can be allowed or prohibited.

Examples

Assuming typical a mask value: u=rwx,g=rx,o=rx which allows all permissions except for write for group and others, the following example shows how a new file (created via touch lacks write for group and others.

The following example disallows write permission for the user class, then creates a file that has no write permission for the user class:

File creation The following table indicates how a digit of the umask mask affects the permissions of a new file if the default permissions include all operations (rwx). The mask value is applied by first negating (complementing) the mask, and then performing a logical AND with the default file mode.

Many operating systems do not allow a file to be created with execute permissions and therefore newly created files have no execute permission regardless of the umask mask.

Use outside file creation In general, the umask mask is only used when creating a file. However, for some implementations of the chmod command, when using symbolic notation and no user is specified, the mask is applied to the requested permissions before they are applied to the file. For example:

Mount option In the Linux kernel, the fat, hfs, hpfs, ntfs, and udf file system drivers support a umask mount option, which controls how the disk information is mapped to permissions. This is not the same as the per-process mask described above, although the permissions are calculated in a similar way. Some of these file system drivers also support separate masks for files and directories, using mount options such as fmask.

See also

References

Worked examples

Example 1 — a first encounter with Umask

Start with the simplest possible case. Write down what Umask claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Umask before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Umask ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Umask

In research
Umask appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Umask in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Umask is common in secondary-school and first-year university syllabi. It links to neighbouring topics File system permissions, IBM i Qshell commands, Unix SUS2008 utilities, so understanding it makes those chapters shorter.
In everyday life
Look for Umask outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Umask” →

How to study Umask in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Umask means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Umask out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Umask in simple terms?

umask is a shell command that reports or sets the mask value that limits the file permissions for newly created files in many Unix and Unix-like file systems. A system call with the same name, umask(), provides access to the mask value stored in the operating system (OS), and the command provides s…

Why does Umask matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Umask?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Umask.

Tags

  • File system permissions
  • IBM i Qshell commands
  • Unix SUS2008 utilities

Keep exploring