Operating System - HP-UX
1753745 Members
5063 Online
108799 Solutions
New Discussion юеВ

Need to set a permission set recursively & automatically for future

 
Arun Jain
Frequent Advisor

Need to set a permission set recursively & automatically for future

Hi All,

I have a directory in which some files are getting created daily but not with the permission set of the folder and as a result we are facing an error on one file system daily.

I need to set a permission set recursively so that every time when a new directory or file is created in that directory, it gets the same set of permission.

Please suggest
Thanks in Advance

Best regards
Arun Jain
speak less say more
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: Need to set a permission set recursively & automatically for future

Hi Arun:

The permisssion bits of a file or directory are established at the moment of creation using open() or creat() with a "mode". This mode is then "anded" with the 'umode' setting. The default mode for files is 0666 and for directories 0777. Hence when running with a 'umask' of 0, a file would have only read/write permissions for the owner, group, and world.

Your recourse may be to periodically, recursively, 'chmod -R 0nnn' your appplication directory.

Regards!

...JRF...
Fredrik.eriksson
Valued Contributor

Re: Need to set a permission set recursively & automatically for future

As JRF said, chmod -R /path/ 0nnn will set the 0nnn permission recursively.

To explain the bitmask abit this is how you decipher it. (for future references)

First n is "owner user" (also designated "u", this is valid for the user assigned by chown).
Second n is "owner group" (also designated "g", this is valid for the group assigned by chgrp)
Third n is "others" (also designated "o", this is for everyone)

You can also use "a" for all of them or write "ugo". It's the same.

You can set permissions via chmod by using letter description or by bitmask.
Using the first method setting all permissions for "owner user" one could write as follows.
chmod u+rwx file.txt

Using the bitmask method you need to know which value r, w and x has.
x is 1
w is 2
r is 4

so a combination of these will create the appropriate rwx combination.
5 = 4 + 1 = rx
6 = 4 + 2 = rw
7 = 4 + 2 + 1 = rwx

therefor, setting -rwxrw-rw- on a file will be 0766.

Hope this clarifies :)
Best regards
Fredrik Eriksson
Roland Piette
Regular Advisor

Re: Need to set a permission set recursively & automatically for future

Hi,

I suggest that you look also at the man page of umask. You can change it in the profile of the user wich creates files.

Roland
Dennis Handly
Acclaimed Contributor

Re: Need to set a permission set recursively & automatically for future

>I need to set a permission set recursively

chmod -R is a very dangerous command. Make sure you don't use it on / or /usr, etc.

You may want to use "chmod xxx path/*".

If you are going to use -R, you should use symbolic patterns so you don't give execute access to files or take them away from
directories.
chmod -R a+w path