1

Is there a way to restrict a directory to have only 1 file?

I created a specific directory for a user and I would like to limit that directory to have only 1 file. If that user wants to store new file, the user has to delete the old file before saving the new file into that directory.

Is this possible? Ideally without having to write any script and use cron job to 'monitor' the directory.

There are a few users that I would like to impose this limit to.

Any suggestion please?

5

1 Answer 1

4

The only way is to have a directory that the user can't write to. Create a single file in that directory and give them permission to write that file. They won't be able to remove the file nor to create another file. They won't be able to rename the file either. But they can overwrite the file, and they can change the file's metadata (timestamps, permissions, etc.) if they own the file.

chown root:root mydir
chmod 755 mydir
touch mydir/somefile
chown bob mydir/somefile

This seems completely pointless to me. There is no possible security benefit to allowing a user to have a single file; there might be a benefit if you additionally constrain the name (as I do here) but even this seems far fetched. Make sure that you're solving your actual problem rather than some made-up nonsensical constraint.

You must log in to answer this question.

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