What is the difference between symbolic links and hard links? — Understanding through inodes

Linux・CLI・DevOpsカテゴリを表すパンダのイラスト Linux / CLI / DevOps

About this article
This article is created using an automated generation workflow leveraging generative AI. After verifying the GNU coreutils ln specification,mktempit is structured to observe links and inodes solely within a temporary workspace.

Verification Status: 📘 GNU official documentation verified / Unverified on actual hardware

Instead of just memorizing names, creating two types of links to the same filels -liand checking the inodes with reveals the difference.

Try it first

d=$(mktemp -d); cd "$d"
printf 'hellon' > original.txt
ln original.txt hard.txt
ln -s original.txt sym.txt
ls -li

Looking at here

original.txtandhard.txtshare the same inode number.sym.txthas a different inode, and displays-> original.txt.

Change one place

rm original.txt
cat hard.txt
cat sym.txt

Observe that while the content can still be read from the hard link side, the symbolic link fails because the target path name has been deleted.

Why does this happen?

A hard link adds another name to the same inode. A symbolic link is a separate file whose content is the path of the reference destination.

graph LR
A[original.txt] --> I[inode/data]
H[hard.txt] --> I
S[sym.txt] --> A

For professional use

While symlinks are useful for configuration switching and similar tasks, broken links must be taken into account. Because hard links have constraints regarding filesystem boundaries and directories, do not assume they are simply a replacement for regular copies.

Cleanup: cd / && rm -rf "$d"

GNU ln: https://www.gnu.org/software/coreutils/manual/html_node/ln-invocation.html

Document information

Article title
What is the difference between symbolic links and hard links? — Understanding through inodes
Published
Updated
Source
https://papanda925.com/?p=15434&lang=en

License: Text and original figures for which this site holds the relevant rights are available under CC BY 4.0 , unless otherwise noted. This article may include content created or edited with generative AI. If code has a separate license notice or a linked GitHub repository license, that license takes precedence for the code. Quotations, third-party materials, images, and trademarks are excluded from this license. Usage policy

Copied title and URL