For question pertaining to the inode (index node), a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Use this tag for questions about the inode data structure itself or questions about issues arising from querying or managing inodes in the scope of a filesystem.
An inode (sometimes referred to as an index node) is the file structure as part of the metadata of many file systems. Each inode typically contains all the information about one file or directory, except its content and name.
The number of inodes (and thus total number of files and directories) is often fixed at filesystem creation; thus they're frequently over-provisioned. The mkfs
default is typically several percent of the total size of the filesystem. The size of an individual inode varies by filesystem; Linux ext[234] uses 128- or 256-byte inodes, for example.
The metadata stored includes the following:
- Inode number
- Access Control List (ACL)
- Extended attribute
- Direct/indirect disk blocks (lists where the actual file contents is stored)
- File access, change and modification time
- File deletion time
- File generation number
- File size
- File type
- Group Number of links
- Owner
- Permissions
- Status flags
Examples
$ touch "test1"
$ touch "test2"
$ ls -il test*
1079211 -rw-r--r-- 1 root users 0 Oct 12 15:13 test1
1079212 -rw-r--r-- 1 root users 0 Oct 12 15:13 test2
The first column is the inode. In addition, both stat
and ls -i
will give you the inode number. The find
command can search for a file by inode number using -inum
.
A file's inode does not store the file's name. (Indeed, hardlinked files share the same inode; a file can have many names). Instead, that is stored by the directory containing the file. If the filesystem is damaged, and the directory entries pointing to an inode are lost, fsck may re-connect the inode (often under a generated name) to "lost+found".
Each file on a filesystem has a unique inode number (though of course two files on two different filesystems can have the same inode number). As above, hardlinks (as created by ln
) share the same inode, so this can be used to confirm two file names are hardlinked together.
Further reading
Find where inodes are being used
What is a Superblock, Inode, Dentry and a File?
How can I increase the number of inodes in an ext4 filesystem?
External reference