0

I'm working through questions from Unix The Textbook.

I'm trying to solve the question (chapter 8, #15, page 207):

  1. Give a command line for setting the default access mode so that you have read, write, and execute privileges, your group has read and execute privileges, your group has read and execute permissions, and all others have no permission for a newly created executable file or directory. How would you test it to be sure that it works correctly?

My initial answer was to use umask 027, but I found that creating a new file with touch or vim never worked as expected for the execute permission as umask was applied to 666 not 777.

Since my end goal is to have a permission value of 750 it seems to me it is impossible with the umask command as any umask applied to 666 will not result in 750.

Given all the questions in this section relate to chmod and umask is the question flawed in that you can't achieve the desired goal using umask?

2 Answers2

1

Well, the question contains this part:

for a newly created executable file or directory.

Newly created executables and directories are probably created with mode 0777, so they would get the execute permissions as wanted, too. So the question seems to be correctly stated and an umask of 027 should do.

ilkkachu
  • 138,973
0

Per these docs you can determine any umask by subtracting from 777 (666 advised for files because they're not exectuable by default).

So you can something like

PERM=750
UMASK=$(expr 777 - $PERM)
echo $UMASK
>>> 27

Note, it's missing that leading zero which might be an issue in some contexts, but works fine if you just want