Inode
lastmod 2025-02-17created 2015-04-205 edits
In computer science, an inode is a data structure used in traditional Unix-style file systems such as UFS. An inode holds information about file system objects such as regular files and directories.
Each file has one inode, and the inode holds information about that file, such as the owner group, access mode (read, write, and execute permissions), file type, and inode number (inode number, i-number). Files within a file system can be identified by their unique inode numbers.
Typically, about 1 percent of the total space is allocated for inodes when a file system is created. Since the space for inodes is limited, the maximum number of files a file system can hold is also limited. In most cases, however, users can create and manage what feels like an almost unlimited number of files.
Hard Link
Creates a file link that has the same inode. Use ls -i to check the i-node number:
Checking the new hard link file shows that the i-node is the same: (the file type is also -)
$ ln f f.h
$ ls -lai
4599473 -rw-rw-r-- 2 yourname yourname 4 Oct 4 20:53 f
4599473 -rw-rw-r-- 2 yourname yourname 4 Oct 4 20:53 f.h
As the number 2 in the third column shows, the Hard Link count is 2.
Of course, the contents of the two files are identical.
Even if you delete the first file, the i-node remains. (And of course the contents are the same.)
However, as the number 1 in the third column shows, the Hard Link count has dropped to 1.
Soft Link
Think of a soft link as a Windows shortcut:
$ ls -li
4599473 -rw-rw-r-- 2 yourname yourname 4 Oct 4 20:53 f
4599473 -rw-rw-r-- 2 yourname yourname 4 Oct 4 20:53 f.h
$ ln -s f f.s
$ ls -li
4599473 -rw-rw-r-- 2 yourname yourname 4 Oct 4 20:53 f
4599473 -rw-rw-r-- 2 yourname yourname 4 Oct 4 20:53 f.h
4618766 lrwxrwxrwx 1 yourname yourname 1 Oct 4 21:02 f.s -> f
You can see that the Hard Link count does not change.
Troubleshooting
Running out of inodes
The -i flag of df shows the number of inodes in use. Check usage repeatedly alongside ls -i.
See also
- Managing Disk Space - Notes on issues when disk space runs low.
Favorite site
- Wikipedia (en) Description of inode
- Zetawiki: Hard link
- inode, hard links, soft links
- inode, symbolic/hard links