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?

  1. Afile 637, directory 750
  2. Bfile 640, directory 750
  3. 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.
Practice this topic Back to topic

Books on Linux and Command-Line Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Linux and Command-Line Basics questions

  1. The directory d has permissions rwx--x--x (711), and the file f.txt in it has rw-r--r-- (644). A user who is neither the owner nor the superuser runs "ls d" and "cat d/f.txt". Which of the following is the result?
  2. Which of the following correctly describes the sudo command on Linux?
  3. On many Linux systems, "ls -l /usr/bin/passwd" shows "-rwsr-xr-x 1 root root ...". Which of the following is the meaning of the "s" in the owner's execute position?
  4. When the commands above are run in order, which of the following is the content shown by the last cat?
  5. As shown above, in a directory where a.txt exists and nofile does not, the last command is run. Which of the following is the result?