What is an Inode

An inode (index node) is a data structure on a Unix filesystem that stores everything about a file except its name and contents. Permissions, owner, size, timestamps, and the addresses of the disk blocks where the data actually lives — all stored in the inode.

How it works

Every file and directory on a Unix filesystem has an inode, identified by an inode number. When you run ls -i, the number in the first column is the inode number.

An inode stores:

  • File type — regular file, directory, symbolic link, socket, etc.
  • Permissions — read, write, execute for owner, group, and others.
  • Owner and group — user and group IDs.
  • Size — in bytes.
  • Timestamps — created, modified, accessed.
  • Link count — how many directory entries point to this inode.
  • Block pointers — addresses of the disk blocks containing the file's data. For large files, these include indirect pointers (pointers to blocks of pointers).

A file name is not stored in the inode. Names live in directory entries, which are simply mappings from a name string to an inode number. This is why hard links work — two different names in two different directories can point to the same inode. The file's data exists once; only the directory entries are duplicated.

When you delete a file with rm, you're removing a directory entry and decrementing the inode's link count. The data blocks are only freed when the link count reaches zero and no process has the file open (via a file descriptor).

Why it matters

Inodes are the reason Unix file operations work the way they do. Hard links, mv being instant on the same filesystem (it just updates a directory entry), and the ability to delete a file while a process still reads from it — all follow from the inode design. Understanding inodes makes filesystem behavior predictable rather than mysterious.

See How File Systems Work for the full storage architecture.