Why does moving a file not affect its inode number?

Moving is actually creating a copy of a file in a new location, then deleting the file from its previous location. Since it is impossible to have two identical inode numbers at the same time, the inode number should change after copying and before deleting the old file (short time). However, I discovered that the inode number does not change after mv command. So, is the inode number of the deleted file reassigned to the copied file?

Answers 1

  • Moving is actually creating a copy of a file in a new location, then deleting the file from its previous location.

    That's not necessarily true.

    If the destination is on the same filesystem, the file is not copied. Only its path is changed, which is part of a directory, not stored in the inode.

    If the destination is on a different filesystem, then the file is copied.

    This is also covered on Stack Overflow: How does Linux's mv work internally?


Related Questions