in reply to How does rename() work on read-only files?

Perhaps it helps to think of a "directory" like just another file, but a special file that contains a list of other files. In order to rename a file, you don't need access to that file itself, you need access to the place where it is listed, the directory. So in the following example, you've got a file foo and two directories, one and two. In order to move the entry for the file foo from one directory to the other, you need write access to both one and two's list of files, and if I take that away, I can't move the file.

$ cd `mktemp -d` $ mkdir one $ mkdir two $ chmod -R 755 . $ touch one/foo $ chmod 0 one/foo $ cat one/foo cat: one/foo: Permission denied $ mv -v one/foo two/ ‘one/foo’ -> ‘two/foo’ $ chmod a-w one $ mv -v two/foo one/ ‘two/foo’ -> ‘one/foo’ mv: cannot move ‘two/foo’ to ‘one/foo’: Permission denied $ chmod u+w one $ chmod a-w two $ mv -v two/foo one/ ‘two/foo’ -> ‘one/foo’ mv: cannot move ‘two/foo’ to ‘one/foo’: Permission denied $ chmod u+w two $ mv -v two/foo one/ ‘two/foo’ -> ‘one/foo’

By the way, if this is about the -i switch and needing a reliable mechanism for "overwriting" files in-place, my module File::Replace might be of interest to you. Update: See Re: [RFC] File::Replace