Linux considers all hardware devices, printers, directories, and processes to be files. A regular file may be any text, audio, video, photograph, or multimedia file. All standard files have metadata that describes everything about the file, such as sort, Inode, and so on.
An inode number in Linux is a row in the Inode table that contains data (metadata) about a regular file or directory. In a traditional Unix-style file system like Ext3 or Ext4, an inode is a data structure.
What is an Inode Number in Linux?
In Linux and other Unix-like environments, an inode number is a unique identifier for all files. When a file is created on a system, it is given a file name and an Inode number.
The inode number, also known as the index number, is made up of the following file attributes:
- Types of files ( executable, block special, etc )
- Permissions ( read, write, etc )
- UID (Unique Identification Number) ( Owner )
- GID ( Group )
- Size of the file
- Last access, last modification, and last inode number change are all included in the timestamps.
- Deletion time
- Number of soft/hard links
- The location of the file on the hard disk.
- Some metadata about the file.
Find the Inodes on the Filesystem
Using the ‘-i‘ option with the df command, you can find the total number of inodes on the disk.
df -i /dev/sda1 Filesystem Inodes IUsed IFree IUse% Mounted on /dev/vda1 1536000 138846 1397154 10% /
The command below displays the total number of inodes on the file system, as well as the number of used and free inodes. You can not generate a new file on disk if inodes are full on any filesystem, even if there is enough free space. To create files, each file system needs free disk space and inodes.
Find a file’s inode number
Use the following command to find the file’s inode number. The first field in the output is the file’s inode number.
ls -il myfile.txt 1150561 -rw-r--r-- 1 root root 0 Mar 10 01:06 myfile.txt
You can also use the find command to look for a file by inode number. As an example:
find /home/rahul -inum 1150561 /home/rahul/myfile.txt
Copy, Move and Delete Inodes
When you copy, move, or delete a file on the filesystem, what happens to the inode number?
Copy file: cp creates a new entry in the inode table by allocating a free inode number.
### 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 the destination filesystem is the same as the source, moving or renaming a file has little effect on the inode number; it just affects the timestamps in the 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: In Linux, deleting a file decreases the link count and frees the inode number for future use.
Remove unused files to free inodes
In case if inodes are full. You will have to remove unused files to make inodes free on the filesystem. On disk, there is no way to increase or decrease inodes. It is only created when a filesystem is created on a disk.
Monetize your Crypto or Bitcoin related website
Calling all aspiring digital moguls in the world of cryptocurrency! If you’ve been captivated by the rise of Bitcoin and…