I am using mkdir in a php script to make file3 in directory /file/file2/file3. I use permission 777 but the file always looks like dr----x--t 2 admin admin 4096 Jul 1 19:26 file3 once it is made. I am running Centos 5 64bit. file2 is permission drwxrwxrwx 16 root root 4096 Jul 1 19:26 file2 already. Anyone have any ideas why this is?
mkdir("/file1/file2/file3",777);
You want to use
777octal, not decimal:777decimal turns out to be1411octal which will give you the bitmask1 100 001 001which is why you’re getting those “strange” permissions. The standard set (last three segments) gives your----x--xand the first segment modifies the world permissions tot(the sticky bit).Also keep in mind that
mkdiris subject to yourumasksetting and may not give you the permissions you ask for (yourumasksetting gets “removed” from the permissions you ask for to give you the actual permissions). See here for details, including how to avoid the problem.You’re better off using
mkdirto create the directory thenchmod(which isn’t affected by yourumasksetting) to change the permissions.