An inode is an entry in inode table, containing information ( the metadata ) about a regular file and directory. An inode is a data structure on a traditional Unix-style file system such as ext3 or ext4.
What is inode number in Linux
Inode number also called index number, it consists following attributes.
- File types ( executable, block special etc )
- Permissions ( read, write etc )
- UID ( Owner )
- GID ( Group )
- Time stamps including last access, last modification and last inode number change.
- File deletion time
- Number of links ( soft/hard )
- Location of ile on harddisk.
- Some other metadata about file.
To check inode number of file use following command. The first field in output is an inode number of the file.
ls -il myfile.txt 1150561 -rw-r--r-- 1 root root 0 Mar 10 01:06 myfile.txt
You can also search file with an inode number using find command. For example:
find /home/rahul -inum 1150561 /home/rahul/myfile.txt
Inode Changes with Copy, Move and Delete
What happens with inode number when copy, move or delete a file on file system.
Copy file: cp allocates a free inode number and placing a new entry in inode table.
### Check inode of existing file ls -il myfile.txt 1150561 -rw-r--r-- 1 root root 0 Mar 10 01:06 myfile.txt ### Copy file with new name cp myfile.txt myfile_new.txt ### Check inode number of new file. Its changed ls -il myfile_new.txt 1150562 -rw-r--r-- 1 root root 0 Mar 10 01:09 myfile_new.txt
Move or Rename a file: if destination is same filesystem as the source, Has no impact on inode number, it only changes the time stamps in inode table.
### Check inode of existing file ls -il myfile.txt 1150561 -rw-r--r-- 1 root root 0 Mar 10 01:06 myfile.txt ### Moved file to another directory mv myfile.txt /opt/ ### Check inode number of moved file. No change in inode ls -il /opt/myfile.txt 1150561 -rw-r--r-- 1 root root 0 Mar 10 01:06 /opt/myfile.txt
Delete a file: Deleting a file in Linux decrements the link count and freeing the inode number to be reused.