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 Answers 2


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.

  • Do you now where I can see the touch command if I want to modify it? I assume it is a C file somewhere. Jun 10, 2017 at 15:03
  • I guess I could just run which touch Jun 10, 2017 at 15:04
  • or not that shows me a compiled version Jun 10, 2017 at 15:04
  • 1
    @PhilipKirkbride, depends on the OS. GNU touch is part of GNU coreutils. Of course your system may have its own method for distributing source (SRPMs, apt-get source, etc.)
    – ilkkachu
    Jun 10, 2017 at 15:06
  • Thanks posting link so I can find it later, cheers github.com/coreutils/coreutils/blob/… Jun 10, 2017 at 15:09

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .