Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing 'mv A B': Will the 'inode' be changed?

Tags:

unix

mv

inode

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.

like image 249
Luv Avatar asked May 22 '12 13:05

Luv


People also ask

Does mv command change 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'.

Does moving a file change the inode?

Yes and No. As long as the directory being moved to is within the same file system, the inode number remains the same. Inode number changes on moving the file to a different file system.

Does copying a file create a new inode?

As explained above, each inode is identified by an inode number. Therefore, when creating or copying a file, Linux assigns a different inode number to the new file. However, when moving a file, the inode number will only change if the file is moved to a different filesystem. This applies to directories as well.

What is an inode what happens to the inode when you move a file within a filesystem?

What happens to the inode when you move a file within a filesystem? An inode is the control structure for a file. If the two filenames have the same inode number, they share the same control structure and are links to the same file. Assume permissions on a file allow you to write to the file but not to delete it.


1 Answers

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.

like image 89
paxdiablo Avatar answered Sep 18 '22 14:09

paxdiablo