Senior
What is the difference between soft link and hard link in Linux?
sobes.tech AI
Answer from AI
In Linux, a hard link is an additional name for an existing file that points to the same inode. Specifically:
- Hard links cannot usually refer to directories.
- Hard links exist only within the same filesystem.
- If the original file is deleted, the hard link still works because it points to the same inode.
A soft link (symbolic link) is a separate file containing the path to another file or directory:
- It can refer to files and directories.
- It can link to objects in other filesystems.
- If the original file is deleted, the soft link becomes broken.
Example of creation:
ln original.txt hardlink.txt # hard link
ln -s original.txt softlink.txt # soft (symbolic) link