umask
The builtin, and the per-process setting it controls, that lists which permission bits are removed from every new file and directory.
In more detail
New files start from 666 and directories from 777, minus the umask. With the common umask 022, files come out 644 and directories 755; with 077 nobody else gets any access. It is inherited by child processes.
Examples
umask 077umask # prints 0022 on many systemsGo: os.WriteFile(path, data, 0o600) is filtered through the umaskPrograms usually request 666 for files and 777 for directories, and the umask clears the bits it names. With umask 027, a new file becomes 640 and a new directory 750: group write and all access for others are removed. It is a subtraction, not a final mode, so the result depends on what was requested.request=666 umask=027 result=640 is the calculation for a new regular file.Related terms
- numeric mode — A permission setting written as three digits, one each for owner, group and others, where read is 4, write 2 and execute 1.
- file permissions — Rules on each file saying which user and group own it and who may read, write or run it.
- command-line argument — A word given to a command after its name, such as the file names in cp a.txt b.txt.
- os.WriteFile — The Go function that writes a slice of bytes to a file in one call, creating it with the permission mode you give if it does not exist.
- octal — Writing numbers in base 8, using digits 0 to 7, which is the usual way to write Unix file permissions such as 600 or 755.
- file mode — The set of permission bits stored with each file that says what the owner, the group and everyone else may do with it.
- octal mode — Writing a file mode as base-8 digits, one per class, where each digit is the sum of read 4, write 2 and execute 1.
- process — A program that is currently running, with its own memory and a numeric identifier.
Taught in
- Permissions And Ownership — Bash Scripting & Command Line Automation
- Securing Pipelines: Secrets Management — Continuous Integration & Continuous Delivery Pipelines
- Files and the os Package — Concurrent Systems Programming with Go
- Directories, Umask And The Sticky Bit — Linux Fundamentals & Systems Administration
- VFAT, ext4 And XFS: Create, Mount, Use — Red Hat Certified System Administrator (EX200) Exam Prep