Symbolic Links: A Filename That Leads Somewhere Else
A symbolic link is a special file that contains the path to another file or directory. The path is an address in the computer's folder structure. Opening the link can take a program to that address, making one file reachable through another name.
The shorter name is symlink. Its destination is the target. Keeping those two things separate explains a puzzle: a link can still exist after the file it points to is gone.
The details below follow Linux behavior, as described in the Linux symbolic-link manual. Other operating systems and particular programs may handle links differently.
- Stop breaking your focus to look up a command: the answer is already under your wrist.
- Find what you need fast, with commands grouped by job from files to networking.
- Enough room for a laptop or a keyboard and mouse, on a soft surface that's easy on your wrists.
One file, another way to reach it
Suppose a project keeps its current instructions at /projects/guide.txt. A symlink elsewhere can contain that pathname. When a program opens the symlink normally, Linux follows the stored path and opens the guide.
The guide hasn't been copied into the link. Editing the target through that route changes the same file that someone reaches through its original pathname. A symlink can also point to a directory or cross from one filesystem—the structure used to organize stored files—to another.
That makes it useful when software expects a familiar name but the actual resource lives elsewhere. It also means the link is no substitute for a backup. If the target's contents are lost, the link has no spare copy to offer.
Now imagine the guide is moved and nothing is placed at its old path. The symlink still contains /projects/guide.txt, but that address no longer leads to the file. The result is a dangling link.
The computer can read the signpost. There simply isn't anything at the named destination.
Removing the signpost leaves the destination
Different file operations treat links differently. An ordinary open operation follows a symlink. Linux's operation for removing that link, called unlink, acts on the link itself and leaves the target alone.
That distinction is why “delete this link” and “change the file reached through this link” can have very different effects. You need to know which operation the program is performing, rather than assume every command follows the same rule.
A hard link is a different mechanism. It names the stored file directly; it doesn't store another pathname to follow. Removing one name doesn't have the same effect as making a symlink's target path disappear. The similar names hide two different relationships with the stored file.
Hard Link or Soft Link? Watch the Difference
When a program follows the wrong path
A link doesn't grant permission to read or change protected data. The danger arises when a program with that permission follows a path someone else can control.
Imagine a maintenance program that has permission to update protected files. It expects to write a temporary report in a shared location. If someone can replace the expected file with a symlink, and the program follows it unsafely, the write may reach a protected file instead.
The program supplies the authority; the link supplies the redirection. MITRE documents this class of mistake as improper link resolution before file access.
Checking a path earlier isn't always enough. If someone can change it between the check and the write, the program may use something different from what it inspected. That's a race condition: the order and timing of events change the result.
Developers can reduce the opportunity by limiting who can replace files in working directories, using safe file-access methods and giving programs only the permissions they need.
Race Conditions: When Correct Steps Happen in the Wrong Order

Unix: A Family History, a Standard and a Set of Permissions

Hard Links and Symbolic Links, Explained Step by Step

QUOTE:
"Amateurs hack systems, professionals hack people."
