Setting default permissions for newly created files and sub-directories under a directory in Linux?
To get the right ownership, you can set the group setuid bit on the directory with
chmod g+rwxs dirname
This will ensure that files created in the directory are owned by the group. You should then make sure everyone runs with umask 002 or 007 or something of that nature---this is why Debian and many other linux systems are configured with per-user groups by default.
I don't know of a way to force the permissions you want if the user's umask is too strong.
How do I change permissions for a folder and its subfolders/files?
The other answers are correct, in that chmod -R 755
will set these permissions to all files and subfolders in the tree. But why on earth would you want to? It might make sense for the directories, but why set the execute bit on all the files?
I suspect what you really want to do is set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find
command. For example:
To change all the directories to 755 (drwxr-xr-x
):
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
To change all the files to 644 (-rw-r--r--
):
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
Some splainin': (thanks @tobbez)
chmod 755 {}
specifies the command that will be executed byfind
for each directorychmod 644 {}
specifies the command that will be executed byfind
for each file{}
is replaced by the path;
the semicolon tellsfind
that this is the end of the command it's supposed to execute\;
the semicolon is escaped, otherwise it would be interpreted by the shell instead offind
Apply directory permissions to all new subdirectories in linux
Most unix command come with a recursive option. In this case:
-R, --recursive
It seems like you are trying to use this, but you have -Rm
. That is not the correct option.
I think what you need is:
sudo setfacl -R -m g:users:rwX,d:g:users:rwX index/
I typically use chmod
instead of setfacl
.
chmod -R 777 *
Linux file default permissions
For changing default permissions of the file created, you can use umask
command. umask
is user mask which is used whenever a new file is created.
umask
is a three digit number with octal base. First digit decides the user permissions, second is for group while third determines the permissions for others.
umask
value is used in inverted/complemented form though. That means to determine the required umask
value for the permissions you want, subtract the permissions (in octal form) from 666. The result should be used as your umask
value. e.g. if you want to set default permissions to rw-r--r--
(which is 644 in octal) subtract 644 from 666. The result (022) is your umask value.
To set value for umask
you can simply use:
umask 022
command.
For your case here, I think you can use
umask 000
CentOS change permissions of newly created folders
Set may set a correct umask.
You can find extra documentation at http://centoscert.com/content/what-umask-and-how-setup-default-umask
You can modify the one in /etc/profile
(replace 022 by 002) if you want to change for the whole system.
But careful, this also impact access rights of 'standard' files (not only folders).
Related Topics
Repeat Command Automatically in Linux
How to Append One File to Another in Linux from the Shell
How to Make Bash Treat Undefined Variables as Errors
Bash Script to Remove 'X' Amount of Characters the End of Multiple Filenames in a Directory
How to Establish Ssl Connection Upon Wget on Ubuntu 14.04 Lts
How to Check If a Key Was Pressed in Linux
Redirecting Stdout with Find -Exec and Without Creating New Shell
Can Docker Solve a Problem of Mismatched C Shared Libraries
How to Calculate CPU Utilization of a Process & All Its Child Processes in Linux
Writing a Putchar in Assembly for X86_64 with 64 Bit Linux
How to Use Gdb in Eclipse for C/C++ Debugging
How to Recall the Argument of the Previous Bash Command
What Are the Rules for Valid Identifiers (E.G. Functions, Vars, etc) in Bash
How to Export the Variable Through Script File