umask Redux

The umask (user file creation mask) command in Unix and Unix-like operating systems is used to set default permissions for newly created files and directories. It dictates how the default permissions are masked (restricted) for these newly created files and directories.

Understanding umask

Permissions are represented by a three-digit octal number:

The values are additive. For example, 2 (write) and 4 (read) combine to make 6 (read and write).

Default Permissions

Typically, the default permissions for new files are 0666 (read and write for everyone), and for new directories, 0777 (read, write, and execute for everyone).

Example Usage

To see the current umask value:

umask

Setting a new umask value, for example, 027:

umask 027

This command would result in new files being created with permissions 0640 (666 - 027) and new directories with permissions 0750 (777 - 027).

Common umask Values

Practical Example

If you execute umask 002, the newly created files will have read and write permissions for the owner and group, but only read permission for others:

touch newfile
ls -l newfile
# -rw-rw-r-- 1 user group 0 date time newfile

In summary, umask is an essential command for controlling default file permissions in a Unix system, ensuring that new files and directories are created with permissions that do not allow more access than desired.

Groups

Assignment 1: Six Degrees of Kevin Bacon

Assignment 1: Lambda Functions

Implementing copy to emulate cp

Pros and Cons of File Descriptors Over FILE Pointers and C++ iostreams

Implementing t to emulate tee