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?
-
How are you creating files? – Matt Ball Mar 24 '13 at 14:58
-
2You can, you just need to change the `umask` for the user creating the files. Making things executable by default is **really not recommended**. – Boris the Spider Mar 24 '13 at 14:58
-
You might want to check out [this][1] topic. [1]: http://stackoverflow.com/questions/580584/setting-default-permissions-for-newly-created-files-and-sub-directories-under-a – rubeh Mar 24 '13 at 15:01
-
@BoristheSpider Actually I don't think it would work. `umask` only lowers the default, not elevating it. – Zhanxiong May 06 '20 at 21:57
3 Answers
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).

- 75
- 1
- 2
-
How does your answer solve the question? As cremefraiche noted in the third answer below: "This is not an acceptable answer. The default umask for files is 666, and you cannot elevate permissions with umask, only set them lower than the default." – Zhanxiong May 06 '20 at 21:55
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.

- 29
- 1
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:
- This is unsafe (did I already mention it? Other did.)
- 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

- 7,623
- 6
- 43
- 58
-
2This isn't just unsafe in theory, it flat doesn't work. Every `umask` I've tried straight up ignores the numbers when it comes to the execute bit. – Caleb Oct 20 '13 at 02:33
-
Well, then I guess it just depends on the flavor of linux your are using. – Jean Oct 20 '13 at 14:43
-
1@Jean Can you give an example of a umask on any system that allows you to create an executable file by default? – pgl Feb 07 '14 at 13:50
-
11This is not an acceptable answer. The default umask for files is 666, and you cannot elevate permissions with umask, only set them lower than the default. – cremefraiche Apr 18 '15 at 01:32
-
2What you do with an apache server for example? Do you continuously update file permissions on new files as you add them? That sounds like a real rigmarole. – Connel May 02 '16 at 12:28