1

I have a directory and I want all files that are put in it to have the permissions of **5. In other words I want the permissions of the owner and group to stay the same but the permission to be read and execute for all other users.

Is this possible? I know I can periodically set the permissions of all the files in this folder but I was wondering if there was a way to automate it.

1 Answer 1

2

You may want to take a look at umask:

umask (user mask) is a command and a function in POSIX environments that sets the file mode creation mask of the current process which limits the permission modes for files and directories created by the process. A process may change the file mode creation mask with umask and the new value is inherited by child processes. When a shell (as with an output redirect) or other program creates a file or directory, it may specify permissions to be granted, however, permissions that the file mode creation mask does not allow are removed.

(from http://en.wikipedia.org/wiki/Umask)

Just set the desired umask mode at the beginning of your bash script to achieve the described effect.

2
  • Thanks man, I appreciate it. See, I have samba on my linux server and when I put files from my windows comp into the share folder, the umask mode changes the permissions as I desired. However when I put files from my linux comp (the server) into the share folder, the permissions don't change
    – user784637
    Dec 18, 2011 at 0:44
  • You could try mounting the folder in your server to a virtual path with the bind option while setting the umask for that bind mount. Then only put files into the bound path instead of the actual folder, i.e. mount --bind -o umask=0117 /home/files/smbfolder /home/files/virtualfolder
    – bkzland
    Dec 18, 2011 at 10:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .