Inodes: Linux Inodes vs File Names for Understanding Filesystem Storage

Linux stores file identity in inodes, not in the names you see in a directory listing. A file name is mainly a readable label that points to an inode, while the inode holds the storage facts: owner, permissions, timestamps, size, block pointers, and link count. On ext4, a directory entry can store a file name up to 255 bytes in length [source: kernel.org], but that name is still not the file itself. This distinction matters when disks look “full,” backups miss data, or a renamed file keeps working as if nothing changed.

TLDR: A Linux file name is a pointer in a directory; the inode is the file’s real identity inside the filesystem. For example, if report.txt and final-report.txt are hard links to inode 1849221, deleting one name does not delete the data. In one server cleanup case, removing 120,000 small cache files freed only 900 MB of space but released 120,000 inodes, fixing failed deployments. When troubleshooting storage, check both df -h and df -i, not just file sizes.

What an inode actually is

An inode is a filesystem record. It describes a file or directory, but it usually does not store the file name. The inode contains metadata such as:

  • File type: regular file, directory, symbolic link, device, socket, or pipe.
  • Permissions: read, write, and execute bits.
  • Ownership: user ID and group ID.
  • Size: the apparent file size in bytes.
  • Timestamps: access, modification, and status-change times.
  • Link count: how many directory names point to the same inode.
  • Block references: where the file’s data lives on disk.

The file name lives in a directory entry. That entry maps a name, such as invoice.pdf, to an inode number. This is why the same file can have more than one name. It also explains why renaming a file is usually cheap. The filesystem changes a directory entry, not the file data.

File names are labels, not identities

Most users think of a file by its path: /home/ana/budget.xlsx. Linux sees that path as a chain of directory lookups. It starts at /, finds the inode for home, then ana, then the directory entry for budget.xlsx. The final result is an inode.

That sounds like a small technical detail. It is not. It affects real operations every day:

  • Renaming a file does not change its inode on the same filesystem.
  • Moving a file within the same filesystem is often just a directory update.
  • Deleting a file removes a name, not necessarily the data right away.
  • Hard linking creates another name for the same inode.

Honestly, it feels like half of storage confusion starts here. Someone deletes a 20 GB log file, runs df -h, and sees no free space returned. The usual reason is simple: a process still has the inode open. The directory name is gone, but the file data remains allocated until the process closes it.

How to inspect inodes on Linux

Use ls -i to show inode numbers:

ls -i
1849221 report.txt
1849221 final-report.txt

If two names show the same inode number on the same filesystem, they are hard links to the same file. Use stat for deeper metadata:

stat report.txt

The output shows the inode number, link count, permissions, ownership, size, and timestamps. The stat system call returns much of this metadata to programs [source: man7.org].

To check inode capacity, run:

df -i

This command lists total, used, and free inodes by filesystem. It matters because a disk can have free bytes but no free inodes. When that happens, creating new files fails. The error may say No space left on device, even when df -h shows gigabytes free. Expect to waste time on this if a build server creates millions of tiny files in dependency folders, cache trees, or session directories.

Inode exhaustion versus disk space exhaustion

Linux filesystems have two storage limits that administrators must watch:

  • Block usage: how much data space is used.
  • Inode usage: how many file records are used.

A video archive usually runs out of blocks first. A mail spool, package cache, Docker overlay directory, or web session store may run out of inodes first. One million 1 KB files can cause more operational pain than one 1 GB file, even if the byte usage looks similar.

This is why cleanup scripts should count files, not just bytes. A command such as find /var/tmp -type f | wc -l gives a rough file count. Pair it with du -sh /var/tmp and df -i. Together, those commands show whether the problem is file count, byte usage, or both.

Hard links: one inode, multiple names

A hard link is another directory entry pointing to the same inode. It is not a copy. If two hard-linked names refer to the same regular file, editing one changes what the other shows because both names reach the same data.

Example:

echo "approved" > status.txt
ln status.txt status-backup.txt
ls -li status*

You should see the same inode number for both names. The inode’s link count rises to 2. If you delete status.txt, the data remains because status-backup.txt still points to the inode. Only when the link count reaches zero, and no process holds the file open, can the filesystem reclaim the data blocks.

Hard links are useful for snapshots, deduplication, and efficient backups. They also create risk. A careless edit to one hard-linked name changes the shared file. Tools that assume “different name means different file” can report misleading results.

Symbolic links are different

A symbolic link, or symlink, is its own inode. It contains a path to another file name. It does not point directly to the target inode in the same way a hard link does.

That difference matters. If the target path changes, the symlink may break. A hard link will still work as long as it exists on the same filesystem and the inode remains valid. Symlinks can cross filesystem boundaries. Hard links usually cannot for regular user workflows.

Why renames are fast

Renaming a file inside the same filesystem is usually quick because Linux updates directory entries. The inode and file blocks stay in place. This is why software often writes data to a temporary file, calls fsync, then renames it into place. The method reduces the chance of readers seeing a half-written file.

Across filesystems, moving is different. A move from one mounted filesystem to another becomes a copy and delete operation. The destination file gets a new inode. Scripts that track files by inode must account for that.

Practical rules for administrators and developers

  • Use df -h and df -i together. Byte space and inode space fail in different ways.
  • Use ls -li when names behave strangely. Same inode means same file content.
  • Restart or signal processes after deleting huge logs. Deleted open files still consume space.
  • Be careful with hard links in backups. Preserve them when needed, but know when they hide shared data.
  • Do not treat path names as permanent identity. Paths can change. Inodes can also change when files are copied.

Common misunderstanding: “I deleted the file, so the space is free”

Deletion removes a directory entry. If that was the last name and no process has the file open, space can be reclaimed. If a process still holds the file descriptor, the inode continues to exist without a visible name. This often happens with logs. The fix is to restart the service, rotate logs correctly, or truncate the file instead of deleting it.

Use this command to find deleted files still held open:

lsof | grep deleted

If a database, web server, or Java process appears there with a huge file, you found the reason space did not return. The annoying part is that normal directory listings will not show the file. The inode is still alive, but the name is gone.

The reliable mental model

Think of the inode as the file’s storage record and the file name as a signpost. A directory is a table of signposts. Hard links add more signposts to the same record. Symlinks add a signpost that points to another signpost.

Once you use that model, Linux storage behavior becomes easier to reason about. Renames stop looking mysterious. Deleted files that still use space make sense. Inode exhaustion becomes a measurable condition, not a vague disk error. For serious Linux work, understanding inodes is not trivia. It is basic filesystem literacy.