4

I want all directories and files to inherit same permissions as parent directory.

1 Answers1

6

You can achieve that with ACLs, check this answer for an introduction: https://unix.stackexchange.com/a/12847/130303

You'll probably need default ACLs to achieve what you want to do. Lets say you have a directory test (with files and dirs already in it) and you want user and group to be able to write and others only to read, you can set default ACLs (recursively) with the first three commands and then set it for the existing files in the other three commands:

setfacl -R -m d:u::rwx test
setfacl -R -m d:g::rwx test
setfacl -R -m d:o::rx test
setfacl -R -m u::rwx test
setfacl -R -m g::rwx test
setfacl -R -m o::rx test

You can check the ACLs with the command getfacl:

$ getfacl test
# file: test
# owner: youruser
# group: yourgroup
user::rwx
group::rwx
other::r-x
default:user::rwx
default:group::rwx
default:other::r-x
Lars
  • 3
  • 1
    I agree that ACL's are the answer but what you've linked doesn't describe default ACL's which is what would give the OP what they want. Also I think answers that are just links elsewhere are generally frowned upon. Usually answers are supposed to be self-contained. If you edit your answer to include the default ACL's that the OP is looking for I'll upvote it. – Bratchley Jun 04 '16 at 16:26
  • Yeah, you are right, I was in a hurry. – Jakob Lenfers Jun 04 '16 at 18:56
  • as simple as is this is the almost best answer. If you replace x with X it's the best becasue files won't get the execute permission that maybe is a most common requirement. – DrLightman Jan 13 '21 at 17:43