The inode number is simply the unique identifier of an inode. It is analogous to a UID or GID. Thus, each inode has exactly one identifier.
To find the inode number of a file, use either ls -i
or stat
.
Each directory in Unix is just a list of (filename, inode number)
pairs. The inode number serves as a "pointer" to find the inode structure itself. The inode in turn records the location of the actual file contents.
An inode number is assigned to an inode when it is created, which is whenever a new file is created.
Edit to address the points below:
This is actually a tricky question. I strongly suspected the answer would be "no", but I wasn't 100% certain so I did some quick research. I found a few sources saying that the inode number can in fact change if a file is moved, although I could not reproduce this behavior locally, so it seems this depends on some external factors. See here for example. Note that the inode number can certainly not change from a move if it has multiple hardlinks, or the hardlinks would break.
Yes. Otherwise it would be possible for the operating system to run out of inode numbers, which would be very bad. This is exactly the same reason process IDs can eventually be reused by the OS.
I addressed this above. Each inode has exactly one inode number.