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

how rename() actually works on read-only files just went over my head.

rename doesn't modify any files; it modifies a directory or two. As long as you have write access to the source and destination directories, you can rename the file.

$ touch foo $ chmod 0 foo $ ls -li total 0 11314128152 ---------- 1 ikegami pg1404028 0 Dec 11 10:11 foo $ perl -e'rename("foo", "bar") or die $!' $ ls -li total 0 11314128152 ---------- 1 ikegami pg1404028 0 Dec 11 10:11 bar $ chmod a-w . $ perl -e'rename("bar", "baz") or die $!' Permission denied at -e line 1. $ ls -li total 0 11314128152 ---------- 1 ikegami pg1404028 0 Dec 11 10:11 bar

Replies are listed 'Best First'.
Re^2: How does rename() work on read-only files?
by j41r (Beadle) on Dec 11, 2018 at 10:55 UTC
    ... you can rename the file

    I agree, but I wonder why the foo's inode is not preserved after the rename() step, even though the documentation says so.

      You are mistaken. rename doesn't change what file (inode) the name points to.

      (I've updated my earlier comment to show the inode numbers.)

        So do you agree with hippo here that the new inode numbers for alpha/foo* in the linked doc are in error?

        Was it the original behaviour of perl in the past, when the author wrote it? The author did a good job explaining it so it's hard to believe it's a mistake.

        Oh, I almost forget it. Thank you ikegami for your answers.