How to create symbolic and hard links
Overview
A symbolic link stores a path to another item, much like a shortcut. A hard link is another directory entry for the same file data.
Symbolic links can cross filesystems and point to directories; hard links usually cannot.
Examples
ln -s ~/Documents/notes.txt notes-link
ln original.txt second-name.txt
ls -li original.txt second-name.txt
readlink notes-link
Options and behavior
ln -s target link-namecreates a symbolic linkln target link-namecreates a hard link-freplaces a conflicting destination and should be used carefully- A symbolic link becomes broken if its target moves
- Hard-linked file names share an inode until all names are removed
Tips and safety
Use absolute targets when a symlink must work regardless of its location; use relative targets when moving the whole directory tree together.
Run ls -l to inspect link destinations before deleting or editing through a link.