What’s the idea behind rm not removing non-writable file by default

permissionsrm

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?

Best Answer

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.

Related Question