up vote 0 down vote favorite
share [g+] share [fb]

On Mac OS X, what is a good way of preventing accidental removal of certain files and folders? I still need to be able to read those files and folders and to add new files to those folders, but I want to jump through hoops if I want to remove any of them.

Any good ideas?

link|improve this question

68% accept rate
feedback

3 Answers

Unset the "writable" flag, or better yet, make them the property of the super user:

chmod -w your files here

sudo chown root:root your files here

You can also use the Finder's "File info" -> "Sharing and permissions" fields to change the file permissions.

link|improve this answer
When I have unset the writable flag, I get a question in the Terminal when I try to delete it: override r--r--r-- user/group for file? However, when I try to delete it using the Finder, the file is just deleted. In other words this doesn't seem to help much... – Svish Feb 27 '10 at 11:22
Unsetting it for the folder seems to be more helpful though... In the Finder I then get a question for authentication if I try to remove the folder and if I try to remove the files in that folder. – Svish Feb 27 '10 at 11:26
feedback

You could check the "locked" checkbox in the "Get Info" dialog. ctrl-click or secondary mouse button on the file -> "Get Info" -> check the "locked" checkbox.

Another way of protecting the file would be setting the immutable flag via command line:

$ chflags uchg <file>

Checkout http://osxfaq.com/Tutorials/LearningCenter/AdvancedUnix/ugp2/page2.ws and

$ man chflags

Greetings

jo

link|improve this answer
Tried that Locked checkbox actually, but then I couldn't add files to the directory. And if I marked all the files as Locked and not the folder, I could still delete the folder and all the files with it. Can have a look at the immutable flag though. – Svish Feb 23 '10 at 14:02
For others reading this answer: Seems checking that Locked checkbox and setting that uchg flag does the same thing. In the answer it can seem a bit like they are two different methods. But in the end they are the same. – Svish Sep 2 '10 at 9:04
feedback

To prevent accidental removal of files in a folder, I have ended up with doing both the suggestions.

  • Make read only
  • Mark as locked / Set the uchg flag

To prevent the folder itself to be removed I have only found marking it as Locked to help. This however also prevents you from adding files to that folder, which might be a bit of a hassle. But it does force you to uncheck and check that flag every time you want to do something in that folder, which might be a good idea if you don't do it too often.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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