home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Unix Power ToolsUnix Power ToolsSearch this book

14.2. How Unix Keeps Track of Files: Inodes

The ability to mumble about inodes is the key to social success at a Unix gurus' cocktail party. This may not seem attractive to you, but sooner or later you will need to know what an inode is.

Seriously, inodes are an important part of the Unix filesystem. You don't need to worry about them most of the time, but it does help to know what they are.

An inode is a data structure on the disk that describes a file. It holds most of the important information about the file, including the on-disk address of the file's data blocks (the part of the file that you care about). Each inode has its own identifying number, called an i-number.

You really don't care about where a file is physically located on a disk. You usually don't care about the i-number -- unless you're trying to find the links (Section 9.24, Section 10.3) to a file. But you do care about the following information, all of which is stored in a file's inode:

The file's ownership
The user and the group that own the file

The file's access mode (Section 1.17, Section 50.2)
Whether various users and groups are allowed to read, write, or execute the file

The file's timestamps (Section 8.2)
When the file itself was last modified, when the file was last accessed, and when the inode was last modified

The file's type
Whether the file is a regular file, a special file, or some other kind of abstraction masquerading (Section 1.19) as a file

Each filesystem has a set number of inodes that are created when the filesystem is first created (usually when the disk is first initialized). This number is therefore the maximum number of files that the filesystem can hold. It cannot be changed without reinitializing the filesystem, which destroys all the data that the filesystem holds. It is possible, though rare, for a filesystem to run out of inodes, just as it is possible to run out of storage space -- this can happen on filesystems with many, many small files.

The ls -l (Section 50.2) command shows much of this information. The ls -i option (Section 10.4) shows a file's i-number. The stat command lists almost everything in an inode.

-- ML

Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.