ln
one file, another nameln makes links. A symbolic link, made with -s, is a small file that points at another path — like a shortcut. A hard link is a second name for the very same data, indistinguishable from the first.
A symbolic link points at a name; a hard link points at the data itself.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
The leading l marks it, and the arrow shows where it points. Its size, 13, is just the length of the path it holds.
A second name is added for the same file. Nothing is copied.
Both names show inode 1311234, and the count after the permissions is 2. Deleting one name leaves the data reachable by the other.
-f replaces the existing link and -n stops ln from descending into the directory it points at. This is how a release is switched over.
Switches
A switch changes how the command behaves. These are the ones used day to day; man ln lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
-s- Symbolic: make a link that points to a path. Without it, a hard link.
-f- Force: replace a link or file that already has the name.
-n- Treat an existing link to a directory as a file, so it is replaced rather than entered.
-r- Relative: work out the relative path to the target for you.
-v- Verbose: print each link made.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
readlink -f currentPrints the final path a link resolves to.
ln -s ../shared/config.yml config.ymlA relative link, which keeps working if the whole tree is moved.
find . -xtype lFinds broken symbolic links — ones whose target no longer exists.
unlink currentRemoves a link without touching what it points to. rm does the same.
In cybersecurity
A link makes a program act on a different file from the one it named.
If a privileged program writes to a predictable name in /tmp, a user can put a link there first and redirect the write to a file of their choosing.
A symbolic link inside a served directory can expose files outside it. Web servers have settings to refuse to follow them.
Deleting a file does not free it while another hard link exists. The kernel restricts hard-linking to files you do not own for this reason.