0

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.

2 Answers 2

1

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.

1
  • 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. Jan 26, 2012 at 18:49
2

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.

2
  • Why are the native files permissions not the same for all utilities? Jan 26, 2012 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, 2012 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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