linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/File system/symbolic-link

kb/filesystem ── File system ── beginner

Symbolic link

A symlink is a separate shortcut file that stores a path to its target. Unlike a [[hard-link]], it has its own [[inode]], and a symlink can point at anything, including something that does not exist.

view as markdownaka: symlink, symlinks, soft-link

What a symbolic link is

ln -s target name creates a small file name with a special flag that marks it as a symlink, and with contents that are a path string pointing to target. This is a separate inode, with its own permissions and timestamps.

When a program opens a symlink, the kernel dereferences it and works with the target instead. Most syscalls are transparent (open, stat, read/write). One that is not is lstat, which looks at the symlink itself rather than the target.

Symlink vs hard link

propertyhard linksymbolic link
inodesame as the targetits own
works across filesystemsnoyes
works on directoriesnoyes
survives target deletionyes (contents stay alive)no (becomes "broken")
size0 (nothing of its own)path length in bytes
shown as a "different file" in ls -liinode matchesdifferent inode plus "-> target"

Broken links

If the target is deleted or renamed, the symlink stays but points nowhere:

bash
ln -s /no/such/path slink
ls -l slink   # shown red/italic in most terminals
cat slink     # No such file or directory

To find every broken symlink in a tree:

bash
find /path -type l -! -exec test -e {} \; -print

Where you see it

  • /usr/bin/python3 → python3.12 (versioned alternatives via update-alternatives)
  • /etc/localtime → /usr/share/zoneinfo/<TZ>
  • In systemd units: /etc/systemd/system/multi-user.target.wants/*.service → /lib/systemd/system/*.service
  • Atomic deploys: the current version is a symlink to a specific release

§ команды

bash
ln -s /etc/passwd ~/users-link

Create a symbolic link to /etc/passwd

bash
readlink ~/users-link

Print the raw path that the symlink points to

bash
readlink -f ~/users-link

-f: dereference recursively to the end of the chain and return the absolute canonical path

bash
ln -sfn /opt/app/v2 /opt/app/current

Atomically switch the symlink to a new target (-f: forced overwrite, -n: do not follow into an existing directory)

§ см. также

  • inodeInodeAn inode is a filesystem record that holds metadata and pointers to a file's data blocks. The filename lives separately, in a directory, and simply points to the inode.
  • hard-linkHard linkHard link is a second name for the same [[inode]]. Both names are equal: the file lives as long as at least one of them exists.
  • fhsFilesystem Hierarchy Standard (FHS)FHS is the standard for what lives in which Linux root directory: /etc holds config, /var holds changing data, /usr holds the distro's static files, /home holds users, /tmp holds temporary files.

§ упоминается в уроках

  • ›beginner-02-files-and-text
  • ›beginner-03-inodes-and-links
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies