4

Is it possible to change the inode of a file. What are the different conditions when the inode of a file can be changed ?

1

1 Answer 1

4

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.

3
  • 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 with cp -a to the original location, it will have the same inode as the first file. Commented 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. Commented 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. Commented Nov 5, 2024 at 1:25

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.