ive following folder

 drwxr-xr-x   7 root root 45056 Nov 25 12:39 data

which include sub dirs and files its all 755 ,

but when i create new file inside these dir its get permission

-rw-r--r-- 1 root root    0 Nov 28  2013 new

how to make new files create in these dir take 755 without doing it manually i tried chmod g+s and nothing happen ,

anytips

The only way to set the bit permissions is via your umask. When a file is created, say with permissions 666 (this is in octal), your umask decides which bits are flipped to 0.

To explain further: rwx rwx rwx is for User Group World respectively. If each bit was set to 1 (111 111 111) this would be 0777 (in octal). 0666 is 110:110:110 or rw_rw_rw. Hope that makes sense.

Your umask will, by default, be 022 - (octal 022). This says which bits are to be kept (0) and which are not (1). (It's slightly non-intuitive that way).

Take a 666 created file: 6 & ~0 = 6 6 & ~2 = 4 6 & ~2 = 4

Thus the created file will have permissions of 644 (rw-r--r--).

Note that the effect of umask is to mask off the bits that are given to the file create call. If the call takes 666, there is no way to make it 755 without doing a "chmod a+x file" manually.

Also, the effect of g+s, setting group suid, is to set the owning group, not the bit permissions. Windows is far more fine grained in this respect (ACLs) but there are file system extensions to add ACL permissions to Linux file systems.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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