Can directories and file inherit same permissions as parent directory?

14,242

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
Share:
14,242

Related videos on Youtube

Lavanya Nidhi
Author by

Lavanya Nidhi

Updated on September 18, 2022

Comments

  • Lavanya Nidhi
    Lavanya Nidhi over 1 year

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

    • Jeff Schaller
      Jeff Schaller almost 8 years
      Strictly permissions, or owner/group?
    • Lavanya Nidhi
      Lavanya Nidhi almost 8 years
      If the permission of a directory is 700,i want all files and directories created to have same permissions
    • spectras
      spectras almost 8 years
      If permission on a directory is 700, other users/groups won't be able to enter it and access its files, no matter the files' permissions.
  • Bratchley
    Bratchley almost 8 years
    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.
  • DrLightman
    DrLightman over 3 years
    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.