2

Say, there is a directory ~/docs with owner boo and group boo and permissions rwxr-x---. Assume there are important files apple.txt and orange.txt in docs which user boo wants to protect from himself (from accidental deletion, e.g. rm -rf /home/boo/*), but it's not an option to change permissions of docs to r-xr-x--- or move the files. What possible solutions are there?

Normal users can't do chattr +i apple.txt orange.txt (and this is Linux-only anyway).

So the only option I can conceive of would be to first chmod 550 apple.txt orange.txt and then hardlink ln ~/docs/apple.txt ~/docs/orange.txt ~/locked/ the files to a directory ~/locked/ and chmod 550 /home/boo/locked/. Is this right? Or is there a simpler way?

1

1 Answer 1

4

You're ruling out the normal methods of preventing deletion, so this calls for a workaround where deletion is possible but not catastrophic.

If apple.txt and orange.txt are symbolic links, then a stray rm -rf in that directory will only remove the symbolic links, not the actual data, so the symbolic links can just be re-created.

If for some reason the files can't be symbolic links then a fancier option would be to use a FUSE filesystem that performs a union mount such as funionfs or unionfs-fuse. Put the important files in a branch other than the main branch so that deleting them will only hide them and not delete them from the underlying storage.

Of course, the most robust way of ensuring that the files aren't lost is to back them up. If you keep a history of the files and not just the latest version, this also protects against accidental overwrite (e.g. >apple.txt instead of <apple.txt). Version control (in a repository that's backed up!) is the ideal way of keeping a history of old versions.

1
  • But with symlinks one has to move the files out of the directory first. Using hardlinks avoids that. Commented Mar 14, 2016 at 22:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.