What's the idea behind rm not removing non-writable file by default? Every time you want to remove a file that is non-writable file for current user but you have a write permission on directory get this warning and you need to pres `y' to confirm deletion:

rm: remove write-protected regular file 

I wonder why are non-writable files treated in such special way? One thing that comes to my mind is that such files are usually user config files that contain user secret data such as encrypted password so rm warns before deleting them. Now, what is the real reason?


It is because the behavior of UNIX is a little counter-intuitive in this case. Many folks are quite surprised when they mark a file read-only and someone is able to delete it. You only need write permissions to the containing directory in order to delete a file. rm is asking you as a courtesy, in case you were hoping it being read-only would protect it.

Using -f (force) will make it do it without pestering you. But use that carefully.

  • be careful when typing "rm -rf *", think. – ChuckCottrill Oct 10 '13 at 0:11
  • 5
    A friend of mine refers to that as "Read Mail Real Fast". :) – kurtm Oct 10 '13 at 6:09

I think you are correct about it prompting because it's set not to be written to. If you are removing the non-writable file you are, in fact, writing to that file. If you don't want to be prompted you could always create an alias the says rm is actually rm -f.

  • I don't think I got your answer correctly. I wonder why rm issues such warning in a first place, why are read only files treated differently from writable files. I know when this warning is shown, I wonder why. – user1042840 Oct 9 '13 at 22:17
  • Because if you set something to be read only it's not suppose to be changed. That includes being removed. If you are root and tell it to remove the read only file anyways it want to confirm that you are not making a mistake. It causes you to rethink your choice. – Jeight Oct 9 '13 at 22:21
  • 1
    @Jeight That's not actually correct. You are not writing to the file when deleting. You are writing to the containing directory. – kurtm Oct 9 '13 at 23:45
  • @kurtm You are correct. That was a typo, but the underlying reasoning is the same. – Jeight Oct 9 '13 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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