Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I interactively execute a command in Linux (zsh, if it matters) with a different umask from the default, for one command only? Perhaps a combination of commands combined in a single line? The new umask should apply only to that command and return to its default value for the next command entered.

Ideally the command would be agnostic to the default umask in force before its entered (in other words, the default umask doesn't have to specified).

share|improve this question
up vote 8 down vote accepted

Start a subshell:

(umask 22 && cmd)

Then the new umask will only alter that subshell.

Note that zsh executes the last command of the subshell in the subshell process instead of forking another one, which means that if that command is external, you're not even wasting a process, it's just that the fork is done earlier (so the umask is done in the child process that will later execute your command).

share|improve this answer

You could wrap it in a shell script. umask inherits to all child processes.


umask 0022
share|improve this answer
Or, if you want to do it in one command line, you can invoke a shell like this, "$ (umask 0022; cmd)" – Rob Bos Feb 23 '13 at 19:11
I confused $ ( with $( in your comment, now I understand: ( umask 0022; cmd ). – donothingsuccessfully Feb 23 '13 at 20:21
whoops, well, at least someone clarified that ^^ – Rob Bos Feb 23 '13 at 23:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.