How to make the newly created files inherit the directory's permissions...?
93,488
You could assign a group ownership to a parent
folder and then make inside files inherit properties.
Assigning group ownership could be set by
sudo chmod -R 660 /path/to/parent
sudo chown -R myself:somegroup /path/to/parent
The group ownership can be inherited by new files and folders created in your folder /path/to/parent
by setting the setgid
bit using chmod g+s
like this:
chmod g+s /path/to/parent
Now, all new files and folder created under /path/to/parent
will have the same group assigned as is set on /path/to/parent
.
Related videos on Youtube
Author by
kiran bbnl
Updated on September 18, 2022Comments
-
kiran bbnl over 1 year
I need to give permission to a directory in such a way that, the newly created files should inherit the same permissions as the directory.
- You may find a duplicate for this question, but it doesn't seems to be answered properly. So please update.
-
muru almost 9 yearsThe person who posted that didn't clearly understand what they were doing.
myself:somegroup
is something you use withchown
, and660
withchmod
. You can't mix one with the other. -
kiran bbnl almost 9 years@muru : Correct...! The following command did work... <sudo chmod -R 777 /path/to/directory> but newly created files are not inheritting the permissions. Whenever running the commands, they are getting altered....
-
Felipe over 2 yearsThis did not work for me. But this did work:
sudo find <path> -type d -exec chmod g+s '{}' \;
-
alchemy about 2 yearsIs there a way to do
chmod g+s /home/user
for the user? I triedchmod u+s /home/user
, but only the group was the same as the parent dir, not the userid. ..or does setting just the gid is enough to placate applications that wont run on files in the user dir not owned by the user? related: superuser.com/questions/471844/… "why-is-setuid-ignored-on-directories"