On Linux allow a file to be read/write but not deleted

1

Is there a way in Linux on a ext4 file system that I can make a file readable and writeable but not deletable?

The directory that the file resides in still needs to be writeable by the owner of the directory.

Brady

Posted 2012-08-22T16:02:14.620

Reputation: 314

What is the use-case? If I can write to a file I can empty it, do you have an application that needs the file to exist even if empty? – RedGrittyBrick – 2012-08-22T17:11:34.020

Kinda spot on. I want to offer a config file for a user that an app will use but it doesn't matter if its empty. – Brady – 2012-08-22T18:43:31.983

Answers

0

If you make the directory not writable, the file cannot be deleted.

choroba

Posted 2012-08-22T16:02:14.620

Reputation: 14 741

The directory still needs to be writeable. I will update question to be more clear – Brady – 2012-08-22T16:06:48.203

@Brady: Does the directory need to be world-writable?  Do you need to prevent the owner of the directory from deleting the file?  (This would probably be impossible.)  If the answers to both questions are ‘no,’ set the directory mode to 755. – Scott – 2012-10-01T20:23:25.743