Making new files automatically executable?

℡╲_俬逩灬. 提交于 2019-12-22 04:33:39

问题


Is it possible to make all newly created files have the execute permission when they are created? Why can't I grant it by default?


回答1:


umask for files is subtracted from 666 and for directories it is subtracted from 777. So if your umask is 002 and you create a directory, you get 775 (777 - 002), and if you create a file you get 664 (666 - 002).




回答2:


The umask merely subtracts default file and directory permissions.

777 initial file permissions
111 execute bit is not set by default
---
666 default file permissions
022 subtract default Unix umask
---
644 voila, final file permissions

The execute bit must be set for the owner to cd into a directory of their creation, so user-execute permission is set, resulting in directory permissions of 744, when using the above umask.

I have found no way to setting which would set the execute, by default. This would be bad mojo, anyway, but I am currently researching for a cyber security course I am writing.




回答3:


In a safe way? No. In an unsafe manner: just change the umask by adding umask xxx in your ~/.bashrc file, where xxx represents the permission mask you wish.

Notes:

  1. This is unsafe (did I already mention it? Other did.)
  2. It may leads to many issues. One being the creation of files disallowed on some systems)

Recommended way:

Only do it for files that actually need the execute permission.

chmod +x /the/file


来源:https://stackoverflow.com/questions/15599951/making-new-files-automatically-executable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!