Set umask to 027.
A normal program creates a regular file with the usual requested mode 666.
What mode is normally created?
Remove the masked bits from the regular-file base mode 666. With umask 027, the result is 640.
Detailed explanation
640Correct. 0666 with umask 0027 produces 0640.
650Incorrect. 0650 does not follow the bitwise masking result.
666Incorrect. 666 is the requested mode before umask is applied.
027Incorrect. The umask value is not the resulting file mode.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); (umask 027; : >"$tmp/file"); stat -c '%a' "$tmp/file"; rm -rf "$tmp"Expected result
640Key points
- File base mode is 666
- umask removes bits
- 027 masks group write and other permissions
Notes
- Environment: POSIX shell / GNU stat
- Use a disposable file or directory when checking chmod calculations.
- Exact permission display can vary slightly with filesystem and distribution defaults.
Foundation review
Place the operation
umask removes permissions; it cannot add execute or other permissions that the creating program did not request.
Check the side effect
Calculate files and directories from their different base modes: commonly 666 versus 777.