My /tmp is set with the following permissions (777) and a 't' at the end.
My umask is set to 022.
When I create a directory under /tmp (tmp/xx) it gets created as 755
as expected.
Yet when I create a file within that directory (/tmp/xx/yy) the permissions
are not 755 they are 644.
Can somebody please explain. Secondly, how do I force the permissions
on a file to inherit the parent directories permissions regardless of what
my umask is set too.
umask
022
ls -ld /tmp
drwxrwxrwt 9 root root 1464 Nov 15 09:14 /tmp
ls -ld /tmp/xx
drwxr-xr-x 2 oracle dba 117 Nov 15 09:17 /tmp/xx
ls -lt /tmp/xx/yyy
-rw-r--r-- 1 oracle dba 0 Nov 15 09:17 /tmp/xx/yyy
umask dosn't set execute bit on files (ie file permissions start with 666 directories with 777)
so for files
666 AND NOT 022 = 644
In Binary:
110110110
111101101 AND
----------
110100100
rw-r--r--
And directories
777 AND NOT 022 = 755
In Binary:
111111111
111101101 AND
----------
111101101
rwxr-xr-x
There is no option to have umask set file permissions the same as their parent directory (and you wouldn't want to do that anyway as execute bit on directories controls searchability and has nothing to do with the execute bit on files within them).
You should only set execute bit on files that are actual commands (like script files or compiled programs).
If you want different permissions to these defaults, use the chmod command to change them after you've created your file.
The t on a directory is the sticky bit and means that only the file owner (or root) can remove files once they are created, even though the directory permissions allow write.