A file system relies on data structures about the files, as opposed to the contents of that file. The former are called metadata—data that describes data. Each file is associated with an inode, which is identified by an integer, often referred to as an i-number or inode number.
Inodes store information about files and directories (folders). Each and every file under Linux (and UNIX) has the following attributes:
- File type (executable, block special etc)
- Permissions (read, write etc)
- File Size
- File access, change and modification time (Remember UNIX or Linux never stores file creation time - this is a favorite question asked in UNIX/Linux sys admin job interviews.)
- File deletion time
- Number of links (soft/hard)
- Extended attribute such as append only or no one can delete file including root user (immutability)
- Access Control List (ACLs)
On many types of file system implementations, the maximum number of inodes is fixed at file system creation, limiting the maximum number of files the file system can hold. A typical allocation heuristic for inodes in a file system is one inode for every 2K bytes contained in the filesystem.
The inode number indexes a table of inodes in a known location on the device. From the inode number, the kernel's file system driver can access the inode contents, including the location of the file, thereby allowing access to the file. A file's inode number can be found using the ls -i command. The ls -i command prints the i-node number in the first column of the report.
File names and directory implications:
- Inodes do not contain its hardlink names, only other file metadata.
- Linux directories are lists of association structures, each of which contains one filename and one inode number.
- The file system driver must search a directory looking for a particular filename and then convert the filename to the correct corresponding inode number.