简体   繁体   中英

Default chmod for new files in one specific folder

I want all new created files and folders in one location on my server to have 777 permissions by default.

Right now, I create them from PHP which is fired from an nginx server. I have managed to give them default nginx owner, but the files still don't have necessary permissions.

Is this possible to do?

Check the function umask() from PHP. For example: umask(000) will make that all subsequently created files will have read and write permissions for owner, group and others.

Try looking in this answer: Default permissions , that takes it's content from here: Default files permissions in a specific folder .

I believe that's what you are looking for - that way all new created files will be created in the default settings.

I am not sure if you can change the default file permissions of a new file, even if you can, I am not sure it's a good idea to set it as 777.

Instead let me propose another technique, use alias and create your custom command which will change the permissions of the new directories as they are created, something like this:

alias chmodd='function _chmodd(){ mkdir "$1" ; chmod 777 "$1" ; }; _chmodd'

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM