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.
Check Inodes on Filesystem
You can find a total number of inodes on disk by using ‘-i‘ option with df command.
df -i /dev/vda1 Filesystem Inodes IUsed IFree IUse% Mounted on /dev/vda1 3932160 41953 3890207 2% /
The below command shows the total number of Inodes on the filesystem, uses and free inodes details. In case of inodes full on any filesystem, you can’t create a new file on disk even you have enough free space. So each file system must have free disk and inodes to create file.
Find Inode number of 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 the filesystem.
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.
Free Inodes on Filesystem
In the case of inodes are full. You need to remove unused files from the filesystem to make Inode free. There is no option to increase/decrease inodes on disk. It only created during the creation of filesystem on any disk.