Last modified: June 11, 2024

This article is written in: 🇺🇸

The Inode

An inode (short for "index node") is a fundamental concept in many filesystems, serving as a data structure that describes a file or a directory. Each inode contains crucial metadata about a file, but not the file's actual data.

Key Characteristics of Inodes:

  1. An inode stores essential metadata such as the file's owner, permissions, size, timestamps (creation, modification, and last accessed), and pointers to the file's data blocks.
  2. Every file or directory has a unique inode number within a given filesystem. This number helps the system efficiently manage and locate the file's data.
  3. To view the inode number and other details of files in a directory, use the ls -li command. The first column in the output displays the inode number.

Example:

$ ls -li
total 8
684867 -rw-r--r-- 1 user user  41 Mar  1 12:34 file1
684868 -rw-r--r-- 1 user user  41 Mar  1 12:34 file2
684869 -rw-r--r-- 1 user user  41 Mar  1 12:34 file3

Here, the inode numbers for file1, file2, and file3 are 684867, 684868, and 684869.

  1. For more detailed inode information about a particular file, use the stat command:

$ stat file1
  File: file1
  Size: 41        	Blocks: 8          IO Block: 4096   regular file
Device: 806h/2054d	Inode: 684867      Links: 1
Access: (0644/-rw-rw-r--)  Uid: ( 1000/    adam)   Gid: ( 1000/    adam)

A hardlink creates an additional reference to the existing inode of a file. It's essentially another name for an existing file on the same filesystem.

  1. Use the ln command to crea a hardlink:

ln existing_file hardlink_name

  1. Deleting a hardlink leaves the original file untouched. However, if you delete the source file, all its hardlinks will still point to its content, as they all reference the same inode.

Symlinks are special pointers that reference the path to another file or directory.

  1. Unlike hardlinks, symlinks can point to objects across different filesystems or even non-existent targets.

  2. Use the ln -s command to create a symlink:

ln -s existing_file symlink_name

  1. To determine the target of a symlink, use the readlink -f command:

readlink -f symlink_name

  1. Deleting the symlink doesn't affect the target, but if the target file or directory is removed, the symlink becomes a "dangling link", pointing to a non-existent location.

Feature Hardlink Symlink
Points across different filesystems No Yes
Affected by changes to its target's attributes Yes (Shares same inode) No (Points to a path, not an inode)
Points to non-existent files No Yes (Can create "dangling links")
Reference Inode of the target Path to the target

Challenges

I. Hard Link Exploration

II. Inode Investigation

III. Library Links Search

IV. Dangling Symlinks

V. Can a filesystem run out of inodes even if there's still disk space available? Research and explain.

VI. Try creating a hard link to a directory. What happens and why?

VII. Multiple Hard Links

VIII. Use the ls command with a flag that indicates the type of file (file, directory, symlink, etc.) for each item in the /etc directory. Which flag should you use, and what are the indicators for each type?

IX. Changing Symlink Targets

X. How much space does an inode typically consume on a filesystem? Research and provide your findings.

Table of Contents

  1. The Inode
  2. Hardlinks
  3. Symlinks (Symbolic Links)
  4. Key Differences Between Hardlinks and Symlinks
  5. Challenges