Junior — Middle
Explain what the umask command means and how it affects created files and directories in Unix-like systems.
sobes.tech AI
Answer from AI
The umask command in Unix-like systems sets the permission mask, which determines which permissions will be disabled (blocked) when creating new files and directories.
When a file or directory is created, the system is given a base set of permissions (for example, 666 for files and 777 for directories). umask subtracts (disables) certain bits from these permissions to restrict access.
For example, if umask is set to 022, then:
- For files, the base permissions 666 minus 022 equals 644 (read and write for the owner, read for the group and others)
- For directories, the base permissions 777 minus 022 equals 755 (read, write, execute for the owner, read and execute for the group and others)
Thus, umask helps to restrict access rights to new files and folders by default, enhancing security.
To view the current umask, use the command:
umask
To set a new umask:
umask 027
where the digits are octal mask values.