Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My umask is 0022

When I create directory using

mkdir mydir

the permissions I get are drwxr-xr-x

However when I create file

touch file

the permissions I get are -rw-r--r--

Why do directories get x(search) permission by default whereas files don't? How are the default settings brought into force? Is there a way to change them (I understand it may not be a good idea to just change them). Just want to experiment.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

First off "x" means different things, depending. For files, it means "allow this to be executed" and for directories, it means "allow access", that is, allow someone to cd into it. I'm glossing over some finer points here. It does not, however, mean "searchable".

Generally speaking, for regular users on a modern linux system, the umask is set to be 0002 (in octal). This means that this mask is used when calculating the effective permissions. The starting place for that is different for directories and files. Making a directory defaults to 0777 in octal. The default for files depends on how the open() call was used by the program, but touch, for example, uses 0666 in octal. So if your umask is set to 0002, you end up with 0664 for files, and 0775 for directories, corresponding to rw-rw-r-- for files and drwxrwxr-x for directories.

You can play with setting the umask using the umask command. I would suggest a careful reading of the chmod(1) man page, too, and definitely look up how the sticky-bit and suid and sgid bits come into play, since these are often where a lot of people get confused.

share|improve this answer
    
Thanks for clarifying the "x" bit for directories. My intent in asking the question was to understand why mkdir and touch give different default permissions for directories and files. –  abc Jan 26 '12 at 18:49

The umask has nothing to say about what permissions will be set. Rather, it only says which permissions will never be set if a tool/utility tries to set them. This is why it is only a 'mask'

If you set umask 0000 then you will see what the native file permissions are for various utilities; they are not always the same as you have noticed.

share|improve this answer
    
Why are the native files permissions not the same for all utilities? –  abc Jan 26 '12 at 18:53
    
@abc it really depends on what the programmer had in mind. Generally, for utilities that create files it is best to not have the execute bit set but require the user to add it explicitly. For utilities that create directories, the execute bit is generally set because that governs whether or not you can cd into it and/or list files within it; something that almost everybody wants by default. –  SiegeX Jan 26 '12 at 19:15

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.