Sobes.tech
Senior

Where are filenames stored in a directory in Linux?

sobes.tech AI

Answer from AI

In Linux, file names in a directory are stored not in the file itself or in a separate table, but within a data structure called an inode (index node) and a directory entry.

A directory is a special file containing a list of entries, each linking a file name to an inode number. The inode stores the file's metadata (permissions, owner, size, data pointers), but not the name.

Thus, file names are stored in the directory's entries, which contain pairs (file name, inode). When the system searches for a file, it scans these entries, finds the needed name, and retrieves the corresponding inode to access the content.

This allows multiple names (hard links) for the same inode, meaning one file can have several names in different directories.