Practical technology learning

Linux Symbolic Links: Resolve a Relative Target from the Link Directory

Linux Symbolic Links: Resolve a Relative Target from the Link Directory — conceptual learning illustration
AI-generated conceptual illustration.

A relative symbolic link stores a path that is interpreted from the directory containing the link. Confusing that directory with the current shell location is a common reason a harmless practice link points somewhere unexpected.

Create a disposable layout

Inside a new local practice directory, create separate notes and shortcuts subdirectories. Put a text file named sample.txt in notes with one synthetic line. Do not use system paths, elevated privileges or existing project files. Keep the entire exercise inside this new directory.

This fits Linux filesystem and command-line foundations for learners in Jaipur. It is a deliberately small lab, not a recommendation to change production deployment links.

Build the link from the practice root

From that root, run ln -s ../notes/sample.txt shortcuts/latest.txt. The relative target text is ../notes/sample.txt. Its meaning is resolved from shortcuts, which contains the new link. The ../ step therefore leads back to the practice root before entering notes.

Inspect the stored target and the content

Use readlink shortcuts/latest.txt to inspect the stored path. Read shortcuts/latest.txt with an ordinary text-reading command and compare it with notes/sample.txt. Changing your shell to a different directory does not rewrite the link's stored target. Use a correct path to the link from that new shell location.

A symbolic link is not an independent copy of the target file. Reading through the link follows the reference, subject to ordinary path and permission checks.

Change only the synthetic target name

Rename notes/sample.txt to notes/sample-renamed.txt inside the lab. Inspect the link again: its stored target still names sample.txt, so following it now fails unless another file exists at that original path. Restore the name or recreate the practice link deliberately after recording the observation.

If you move a whole directory tree while preserving the same relationship between a relative link and its target, the link may continue to resolve. Moving only the link or only the target is a different operation.

Distinguish the three things in your notes

  • The path used by your shell to locate the link.
  • The target text stored inside the symbolic link.
  • The filesystem object found after resolving that target text.

Finish with an explanation

Save the small directory sketch, command, readlink output and expected renamed-target failure. Avoid broad cleanup commands; leave removal of the disposable folder to a deliberate review of its path. Explore the related Mango Engineers Linux learning path for broader filesystem and administration foundations, and confirm current coverage separately.

Primary references

Browse more practical learning articles