Course contentsShow
← Computer Science
Lesson 1419 of 2,87232. File SystemsFree lesson

Hard Links vs Symbolic Links

Comparing direct inode references with pathname-based links and their differing semantics and use cases.

Hard Links vs Symbolic Links

What you'll learn: You'll understand the fundamental difference between hard links (direct inode references) and symbolic links (pathname-based pointers), and when to use each.

The Core Difference

A hard link is an additional directory entry that points directly to the same inode as the original file. Both the original filename and the hard link are equals—they're just two names for the same underlying data on disk. The file's reference count increases, and the data only disappears when all hard links are deleted.

A symbolic link (symlink) is a special file that contains a pathname string pointing to another file. It's like a shortcut or alias. The symlink has its own inode but stores the target's path instead of actual file data.

Key Semantic Differences

Hard links:

  • Must point to files on the same file system (same partition)
  • Cannot link to directories (prevents cycles in most systems)
  • Survive if the original filename is deleted—the data persists
  • Share the same inode number and physical storage

Symbolic links:

  • Can cross file system boundaries
  • Can point to directories
  • Break if the target is deleted or moved (become "dangling")
  • Have their own separate inode containing the target path

Use Cases

Use hard links when you need multiple equally-valid names for the same file within a partition, ensuring data persistence regardless of which name gets deleted.

Use symbolic links when you need flexibility: linking across file systems, linking directories, or creating shortcuts where you want clear "original vs reference" semantics.

Think of hard links as multiple keys to the same house, while symbolic links are written directions to that house—if the house moves, the directions become useless.

Key Takeaway: Hard links are direct inode references that share storage and persist together; symbolic links are pathname-based pointers that offer flexibility but can break if targets move or disappear.