How to Create Symlinks with the Linux ln Command
A symlink is a shortcut that points at another file or directory. ln -s /usr/bin/python3 /usr/local/bin/python makes a link named python that points at python3. Symlinks keep one real file while letting many names use it.
Create a symlink with ln -s
Give ln -s the target first, then the link name. Order matters: ln -s TARGET LINK.
Symlink to a command
The classic use is providing a versioned binary under a simple name, so scripts always find it:
Spot symlinks and broken links
In ls -l, symlinks show an l as the first character and the target after an arrow. A link whose target has moved shows in red in most terminals. Use find with -xtype l to find broken ones.
Relative or absolute targets
If the target is relative, it is resolved from the link's location, not your current directory. Prefer absolute paths unless you move the link and target together.
Symlinks vs hard links
A symlink is a pointer that breaks if the target moves. A hard link (ln without -s) is another name for the same file data and survives moves, but only within one filesystem. Most of the time you want a symlink. See ln for details.
Keep learning
Related guides: How to Find Files and Directories with the Linux find Command · The Linux ls Command: List Files Like a Pro · How to Move and Rename Files with the Linux mv Command. Read all tutorials on the Learn Linux blog.