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
