inode in Linux - snir1551/DevOps-Linux GitHub Wiki

inode in Linux

Definition

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.

Important:

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.

inode Contain

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 Relationship Between a File Name and an 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.

Example of How it Works

  1. You run the command: cat /etc/passwd
  2. The system searches for the file passwd in the /etc directory.
  3. It finds the inode number corresponding to passwd.
  4. The system uses the inode to locate and read the file’s data blocks.
  5. The contents are displayed.
⚠️ **GitHub.com Fallback** ⚠️