6

If we execute a command:

mv A B

then what will happen to the fields in the inode of file A? Will it change?

I don't think that it should change just by changing the name of the file, but I'm not sure.

ArjunShankar
  • 23,020
  • 5
  • 61
  • 83
Luv
  • 5,381
  • 9
  • 48
  • 61

2 Answers2

9

It depends at least partially on what A and B are. If you're moving between file systems, the inode will almost certainly be different.

Simply renaming the file on the same system is more likely to keep the same inode simply because the inode belongs to the data rather than the directory entry and efficiency would lead to that design. However, it depends on the file system and is in no way mandated by standards.

For example, there may be a versioning file system with the inode concept that gives you a new inode because it wants to track the name change.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • If we are in the same file system, then? – Luv May 22 '12 at 13:22
  • 1
    @Luv - I find the explanation on [this page](http://teaching.idallen.com/dat2330/04f/notes/links_and_inodes.html) quite useful. A directory is simply a mapping from 'name' to 'inode'. So an `mv` that does not need to physically move data will simply be a change in a directory entry. Not a change in 'inode'. – ArjunShankar May 22 '12 at 13:44
  • 1
    @paxdiablo - This is a good answer. Your point about versioning filesystems is interesting. It would be pretty costly to have sane behavior for example, if there are hard links pointing to the file that was `mv`ed. – ArjunShankar May 22 '12 at 13:55
0

It depends.

There is a nice example on this site which shows that the inode may stay the same. But I would not rely on this behaviour, I doubt that it is specified in any standard.

quazgar
  • 4,304
  • 2
  • 29
  • 41