Linux and Command-Line Basics
touch creates a new file from 666, and mkdir a new directory from 777, with the umask bits removed. Which of the following is the correct pair of permissions when a new file and a new directory are created in a shell whose umask is 027?
- Afile 637, directory 750
- Bfile 640, directory 750
- Cfile 750, directory 750
Show answer and explanation
Answer: B. file 640, directory 750
The umask gives the permission bits to "remove" from newly created files and directories. 027 removes write (2) from the group and read, write and execute (7) from others, so a file becomes rw-r----- (640) from 666 and a directory becomes rwxr-x--- (750) from 777. This is not octal subtraction but bitwise removal (666 AND NOT 027). With the commonly used umask 022, the same calculation gives 644 for files and 755 for directories.
- A. This is 027 subtracted from 666 in octal. The umask removes bits one by one, so the result can differ from subtraction (with 022 both give 644).
- B. Correct. A file goes from 666 to 640 and a directory from 777 to 750.
- C. Files are created from 666, not 777, so a new file does not get execute permission.