Introduction to Linux Inode
In Linux operating system, the inode is nothing but metadata of the Linux file system. It will store all the information of the file and directory except the file or directory name and the data present in it. The Linux file system depends on the inode to search or identify the data on the file system. It is also useful to find the data in a quick manner.
Each inode has associated with its own inode number. It is unique to the Linux file system. But sometimes the inode value may similar to two files. It will depend, how the file is pointing or refereeing to each other.
df [ INODE OPTION... ] [ FILE / DIRETORY / PARTITION PATH ]
- df: The df command referring to get the information of inode. The df keyword in the command | syntax. It will take two sets off an argument as an inode option and the file path. Accordingly, it will provide the inode information on the current machine.
- INODE OPTION: We can provide the different flags as inode options that are compatible with the df command.
- File Path: The path or name of the file.
How Linux Inode Works?
In the Linux ecosystem, all the inodes are present in a single table. It will maintain all the file/directory information. Below are the lists of information that will present in the metadata table
- File types – executable, block special
- Permissions on the file – read, write, executable
- Owner Information – UID
- Group Information – GID
- Size of the file
- Updated file timestamps – last access, last modification, and last inode number change.
- File deletion time
- Number of links including the soft and hard links
- Some other metadata of the file.
Using the inode metadata table, we can identify the inode value or number. The file system can easily calculate the offset value and identify the location of the inode. In source code, the inode number is declared as an “i” and it is a 32-bit unsigned long integer. It means the inode number is an integer value with the size of 2^32 near to 4 billion inodes (That is the theoretical maximum number)
In the older version of the Linux file system (like ext3). All inode will create at the time of file system creation. The major issue with the older file system is storage. Due to all inodes are used then no new files will store. Even if the storage space is available in the drive. But in the new version of the file system. The inode is creating as per the need. Hence the lack of false will not happen.
Examples to Implement Linux Inode
Following are the examples of Linux inode as given below:
Example #1 – Check the Inodes on File System
Generally, the Linux file system is mounted on “/” partition. We can check the current status of inodes i.e. the total number of inodes, inodes used and inodes free. To get the above information, we need to use the “-i” option with df command.
df -i /dev/sda3
Explanation: AS per the above command, we are able to get the inode information of “/dev/sda3” partition. On the same partition, the Linux file system rest. The output window providing the below information.
- File system: The path of the partition on which the file system being reported.
- Inodes: The total numbers of available inodes in the current file system.
- IUsed: The total numbers of used inodes in the current file system.
- IFree: The total numbers of free inodes in the current file system.
- IUse%: The overall percentage of used inodes in the current file system.
- Mounted on: It will display the mount point of the partition storage.
Example #2 – File Inodes
In the Linux ecosystem, we are able to see, which inodes number is associated with the individual file in the Linux file system. To get the file inode information, we need to use the “-i” option with df command.
ls -i file.txt
Explanation: In inode metadata, we are able to get the file information but the file name is not present in it. To overcome this condition, we can use the above command and get the inode information of the file. Basically, it is vice a versa concept to get the file information from the associated inode to the file.
Example #3 – Directory Inodes
In the Linux system, we are able to see, which inodes value is associated with the individual file. Similarly, we can also get the inode information for the directory also. To get the directory inode information, we need to use the “-i” option with df command.
ls -lid data/
Explanation: As per the above command, we are able to get the inode number associated with the individual directory. It will also display the extra information of inodes as compare to the file inode command.
Example # 4 – Inode Changes (While Copy)
In the Linux file system, whenever any operation any happens on the file. The associated inode number will change.
cp file.txt /opt/
ls -i /opt/file.txt
Explanation: When we are copying the files or data from one location to another location. Then the updated or copy location inode value will change. It will not similar like previous inode value. As per the below output (refer screenshot 1 (b)), we are copying the file “file.txt” from data directory to “/opt/”. After copying the data, the inode value was changed.
This is a guide to Linux Inode. Here we also discuss the introduction and how Linux inode works? along with different examples and its code implementation. you may also have a look at the following articles to learn more –