Before anyone tags this question as duplicate, I would like to emphasize that I would like to know something extra...

I found a way to set the default file permissions for all files created in a directory

If I apply this procedure to a directory my_dir all the files and subdirectories that will be created inside my_dir will have the correct permission. But if I create a file outside my_dir and then copy or move it inside my_dir, it won't have the permission defined in my_dir.

So I'd like to know if there's a way to fix the permission of a directory and its contents for all files that are inside that directory no matter where the files have been created.

The best solution would be one where the user has nothing special to do. Simple click and drag, copy, cp, mv... but nothing to do with chmod or so. Therefore an answer like this is not really what I'm looking for because the user will have to do something unusual anytime he wants to copy or move a file.

PS: the reason why I'd like to do that is because I share some folders with colleagues who are in the same group as me. I want that anyone in that group has the right to wrx any file contained in the shared folders even if the files have been created outside the folder.

  • Check the ACL explanation on this superuser.com/questions/237802/…
    – jcbermu
    Mar 6, 2015 at 10:22
  • When you assign an ACL to a directory, all the objects copied /moved to that directory will inherit the permissions assigned. That's just the thing you need. Keep in mind that every possible solution will need rootprivileges to apply it.
    – jcbermu
    Mar 6, 2015 at 10:47
  • 1
    @jcbermu, as far as I've tried the setfacl works well for files created in the directory but doesn't for files that are moved into it.
    – PinkFloyd
    Mar 6, 2015 at 10:52

3 Answers 3


Use the file permission groups for your users. Request from your admin to establish a new group in /etc/groups, add all the team users to that group. Change the umask definitions in the user's shell profile to allow the access for members of the same group.


Write wrapper scripts for cp, mv, etc., that do the chmod after copying.

  • yeah, but some of my colleagues won't be happy to use the terminal for copy/move files. this is why I'd like to find a really really "user friendly" solution... but thanks
    – PinkFloyd
    Mar 6, 2015 at 10:53

If ACLs won't cut it then the fallback solution is to use the inotify API. This allows a program to watch for events within one or more directories and act on them.

Something like this, wrapped up in a script that's started as root at boot time, will get you on your way:

inotifywait --monitor --recursive --quiet --event close_write,moved_to --format '%w/%f' "$TARGET_DIR" |
    while read FILE
        chmod go=u,o-w "$FILE"
        # chown someone:somegroup "$FILE"
        logger -t inotify "Tickled $FILE"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .