Using chmod
I could set the permissions for a file, but if the parent ( ..
) directory had conflicting permissions, what would happen?
And if I create a new file, using touch
or something similiar, how are the initial permissions calculated? Are permissions inherited it from ..
?
And why can't I do anything in directory when I removed the executable
permission flag?
$ mkdir temp;
$ chmod -x temp;
$ touch temp/a;
$ ls temp;
touch: cannot touch `temp/a': Permission denied
Best Answer
There is -strictly speaking- no such thing in UNIX as "conflicting permissions": access permissions on an filesystem entry (directory, file, etc.) determine what you can or can not do on that object. Permissions on other filesystem entries do not enter into the picture, with the exception of the "x" bit on all ancestors directories in the path to a file (up to
/
) -- see 3.The default permission on a newly created file are determined by the permissions that the creating program allows (the
mode
argument to theopen
orcreat
system calls) and the current processumask
. Specifically, any bit that is set (1) in the "umask" is reset (0) in the newly-created file permissions: in C-like notation:file_permissions = open_mode & ! umask
. Readman 2 creat
(look forO_CREAT
) andman umask
for the details.The "x" (executable) bit on a directory controls whether you can traverse that directory: traversing a directory means being able to
cd
into it and access files contained in it. Note that the ability to list the contents of the directory is controlled by the "r" bit.Further reading: