问题
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:
- 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
来源:https://stackoverflow.com/questions/15599951/making-new-files-automatically-executable