2

Is there a way (with acl's) to protect the contents of a folder? Users should create files inside a folder but not overwrite/edit/delete them. Is this possible?

  • Also not allowed to edit/delete own files ? I don't think that is possible. The owner of a file could always change its permissions. – pLumo Jan 23 at 13:40
1

One might use inotifywait to watch the directory and make changes, such as changing ownership of each new file copied into the directory. In a Debian-based distribution, install the software as follows: apt-get install inotify-tools.

Create a script, perhaps /usr/local/sbin/inbox.sh, as follows.

#!/usr/bin/env bash
inotifywait -m -e create "/path/to/directory" |
while read path event file; do
    if [ "$event" = "CREATE" ]; then
        chown root:root "$path$file"
    fi
done

Give the script permission to execute (chmod 0700 /usr/local/sbin/inbox.sh). Then run it at boot time from, say, /etc/rc.local or whichever RC file is appropriate: /usr/local/sbin/inbox.sh &.

According to the manual, -m monitors indefinitely, and -e watches for a specific event. Within the while loop, it could be possible to receive an event such as CREATE,ISDIR, which indicates the creation of a directory, of course. Directories are not the target of the question; thus the if statement contains a command to respond only to new files, which are represented with the event, CREATE. The path variable from inotifywait has a trailing slash character, so $path and $file can be concatenated without specifying a slash between the two.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.