inode in Linux - snir1551/DevOps-Linux GitHub Wiki
An inode (short for index node) is a fundamental data structure in the Linux file system that represents each file, directory, or object stored on the disk.
Every file in the system is assigned a unique inode number that serves as its identifier.
An inode does not store the file’s name. The file name is stored in a directory entry that maps the name to the corresponding inode.
Field | Description |
---|---|
mode | File type (regular file, directory, symlink, etc.) and permissions (rwx). |
uid | User ID (owner of the file). |
gid | Group ID (group ownership). |
size | Size of the file in bytes. |
timestamps | Access (atime), modification (mtime), and change (ctime) times. |
block pointers | Pointers to the data blocks where the file content is stored. |
link count | Number of hard links pointing to this inode. |
- The file name is stored in a directory entry along with the inode number.
- When you access a file, the system looks up the file name in the directory, retrieves the inode number, and then uses the inode to locate the actual data blocks.
- For example: ls -i /etc/passwd → Shows the inode number of the file /etc/passwd.
- You run the command: cat /etc/passwd
- The system searches for the file passwd in the /etc directory.
- It finds the inode number corresponding to passwd.
- The system uses the inode to locate and read the file’s data blocks.
- The contents are displayed.