Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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.

share|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

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.

share|improve this answer

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 and

$ man chflags
share|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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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