Overview
This post summarizes the differences between symbolic links and hard links.
Prerequisites
- inode
- Data structure
- Holds attribute information on the file system (creator, group, creation date, etc.) as data
- You can check the inode number with
ls -i1 /orstat /
What is a Symbolic Link?
- Adds a directory entry that references the path of the original file or directory
- Experiment
touch a.md
ln -s a.md a_symbolic_link.md // Create a symbolic link
ls -i1 a.md a_symbolic_link.md // You can confirm that the inodes are different
- Cannot be referenced if the original file is moved
- Deleted if the original file is deleted
- Can be referenced across different file systems
What is a Hard Link?
- Adds a directory entry that references the inode of the original file or directory
- Experiment
touch a.md
ln a.md a_hardlink.md // Set a hard link
ls -i1 a.md a_hardlink.md // You can confirm that the inodes are the same
- No effect if the original file is moved
- Not deleted if the original file is deleted
- Can only be referenced within the same file system