Inodes — How Linux Tracks Files

Every file on a Linux filesystem has an inode. The inode is the file's true identity — a data structure that stores everything about the file except its name. Understanding inodes explains a lot of Linux behavior that otherwise seems mysterious.

What an Inode Contains

An inode stores all file metadata — but not the filename. The filename lives in the directory entry that points to the inode.

$ stat /etc/passwd File: /etc/passwd Size: 2847 Blocks: 8 IO Block: 4096 Inode: 655370 Links: 1 Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) Access: 2024-01-15 09:00:01 Modify: 2024-01-10 14:22:33 Change: 2024-01-10 14:22:33

An inode contains:

  • File type (regular, directory, symlink, device, etc.)
  • Permissions (rwxrwxrwx)
  • Owner UID and GID
  • File size in bytes
  • Timestamps: atime (last access), mtime (last content modify), ctime (last metadata change)
  • Link count (how many directory entries point to this inode)
  • Pointers to the data blocks on disk

Notice what's not there: the filename.

Directories Are Just Name→Inode Tables

If the inode doesn't store the filename, where does it live? In the directory. A directory is just a special file containing a table that maps filenames to inode numbers. When you run ls, the kernel reads the directory's table and looks up metadata for each inode number it finds.
# Conceptual view of what a directory stores: # Filename → Inode Number # . → 12345 (this directory itself) # .. → 12300 (parent directory) # passwd → 655370 # shadow → 655371 # hosts → 655372 # See inode numbers with ls -i ls -i /etc/ | head -5

The Inode Table

When a filesystem is created (mkfs.ext4), a fixed number of inodes are pre-allocated — the inode table. This number is based on the filesystem size (typically 1 inode per 16KB). You can't add more inodes later without reformatting.

Can I really run out of inodes even with disk space left? Yes. If you create millions of tiny files (like cached files, email messages, or build artifacts), you can exhaust the inode count while plenty of disk space remains. The error looks like "No space left on device" even when df shows space available.
# Check inode usage df -i # Filesystem Inodes IUsed IFree IUse% # /dev/sda1 3276800 45000 3231800 2% # Check inode count when creating filesystem mkfs.ext4 -N 4000000 /dev/sdb1 # specify inode count

Working with Inodes

# Find inode number of a file ls -i file.txt # Find a file by inode number (useful when filename has special chars) find / -inum 655370 # Delete a file by inode number find . -inum 655370 -delete # View full inode details stat file.txt
When does the kernel free an inode? When the link count drops to 0 AND no process has the file open. This is why you can delete a file while a process is using it — the directory entry (name) is removed immediately, but the inode and data blocks persist until the process closes the file.

Frequently Asked Questions

What will I learn here?

This page covers the core concepts and techniques you need to understand the topic and progress confidently to the next lesson.

How should I use this page?

Start with the overview, then follow the section links to deepen your understanding. Use the table of contents on the right to jump to specific sections.

What should I read next?

Use the navigation below to continue to the next lesson or explore related topics.