Is it possible to change the inode of a file. What are the different conditions when the inode of a file can be changed ?
-
Why do files sometimes change but not the inode or vice versa? is related, but not a duplicate — why files sometimes change inode behind the scenes, vs can you explicitly change the inode.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2017-02-18 23:51:22 +00:00Commented Feb 18, 2017 at 23:51
Add a comment
|
1 Answer
The inode is actually what identifies the file (rather than any filename, say). That's why hardlinks work in the first place.
So the only way to change the inode number is to copy the file to a new file (which then would get a new inode).
The filesystem is responsible for managing the inodes, you can't just "choose" one you like.
-
That's not certainly true, as file system caches inodes. so if you copy your file with
cp -a, delete the old file, and copy back new file withcp -ato the original location, it will have the same inode as the first file.Alireza Mohamadi– Alireza Mohamadi2021-09-19 08:50:49 +00:00Commented Sep 19, 2021 at 8:50 -
@AlirezaMohamadi — That's not true. If you cp -a, rm, cp -a your final file will still have a different inode number from your original file.Bobby Jack– Bobby Jack2024-10-22 11:34:42 +00:00Commented Oct 22, 2024 at 11:34
-
@BobbyJack At least when I tested with xfs, what Alireza said is true. After deleting the old file, when I copied the new file back to the original location with
cp -a, the file gets the old inode back.syockit– syockit2024-11-05 01:25:20 +00:00Commented Nov 5, 2024 at 1:25