Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to set the default permissions for newly created directories to have r-x for others and those of newly created files (non-directory files) to have ---.

If I set the umask to 2, directory permissions get r-x but files' get r--.

I couldn't find any way to achieve what I want with umask.

Ultimately, I want others to be able to traverse the directories but not to read the content of the files. I think that is a very reasonable demand but eventually there seems to be no such setting.

share|improve this question
    
Wait, you want no access permissions on the files at all? Not even for their owner? –  Jonathan Landrum May 27 at 13:01
    
no. I'm talking about for others. I want to set directories to be r-x and files to be --- for others using umask. –  Marcus Thornton May 27 at 13:07
    
Why not do something like chmod 600 foo.bar? I know that's not using umask, but it works. –  Jonathan Landrum May 27 at 13:10
    
I want it to be the default setting. Using chmod, it only works on the existed files and the new files and directories still be using default setting. You have to use chmod every time once you have new files. –  Marcus Thornton May 27 at 13:13
    
What about setting up a separate mask for files? –  Jonathan Landrum May 27 at 13:16

1 Answer 1

up vote 5 down vote accepted

If you only create directories with the mkdir command at the shell prompt, you could have:

umask 7
mkdir() (umask 2 && command mkdir "$@")

In your shell customisation file (~/.zshrc for zsh, ~/.bashrc for bash...).

That is set the umask to 7, but redefine mkdir to a function where the real mkdir is called (with the same arguments ("$@")) with a umask of 2. (note that the (...) create a subshell, so the umask 2 is only applied within that function).

share|improve this answer
    
What does "$@" stand for? I haven't seen this before. I create directories not only at the shell prompt but using java programs. –  Marcus Thornton May 28 at 9:22
    
"$@" provides all the arguments passed to the program. Which would be the directory name(s) passed to the mkdir function in this case. –  Chirag64 May 28 at 9:38

Your Answer

 
discard

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.