How-to

How to Create and Manage Symbolic Links on Linux

A symbolic link is a small file that points at a path. It is how Linux enables nginx sites, switches app releases and exposes tools in /usr/local/bin.

What is the ln -s syntax?

ln -s TARGET LINK_NAME
ln -s /opt/restic/restic-0.17.3 /usr/local/bin/restic

The target comes first, the new link second, the same order as cp. The target does not have to exist when you create the link; ln stores the path as text. If you leave out the link name, ln creates a link with the target's base name in the current folder.

How do I see where a link points?

ls -l /usr/local/bin/restic
readlink /usr/local/bin/restic
readlink -f /usr/bin/python3
namei -l /etc/nginx/sites-enabled/shop.conf

ls -l shows link -> target. readlink prints the stored path, and -f follows every link in the chain to the final file. namei -l walks each part of a path and shows permissions along the way, which is great for "permission denied" puzzles behind links.

Should the target be absolute or relative?

An absolute target such as /srv/app/releases/42 keeps working wherever the link is moved, but breaks if the whole tree moves. A relative target is resolved from the folder that contains the link, so it survives moving or copying the whole tree, for example into a backup or a container image.

cd /etc/nginx/sites-enabled
sudo ln -s ../sites-available/shop.conf .
ln -sr /srv/app/releases/2026-12-03 /srv/app/current

-r asks ln to compute the relative path for you. Relative links are usually the better choice inside a project or config tree.

How do I switch a link to a new target safely?

The classic release pattern keeps several versions and points current at one. Switching must be atomic, so no request ever sees a missing link:

ln -sfn /srv/app/releases/2026-12-03 /srv/app/current.tmp
mv -T /srv/app/current.tmp /srv/app/current

-f replaces an existing link and -n treats a link to a folder as a plain file instead of descending into it. Without -n, ln would create the new link inside the old target folder, a common surprise. The mv -T rename is atomic on the same filesystem, so the switch happens in one step. Rolling back is the same two lines pointing at the previous release.

How do I remove a link without touching the target?

rm /usr/local/bin/restic
unlink /srv/app/current

Removing the link never affects the target. Be careful with trailing slashes: rm -r /srv/app/current/ with a slash follows the link and deletes the contents of the folder it points at. Without the slash, only the link goes. unlink refuses to remove anything but a single file or link, which makes it a safe habit.

How do I find broken links?

find /etc /usr/local -xtype l
find /srv -xtype l -print -delete

-xtype l matches links whose target does not exist. Review the list before adding -delete. Broken links pile up after package removals and manual installs; they are harmless but confusing. More find tricks are in The find command guide.

How is a symbolic link unlike a hard link?

PropertySymbolic linkHard link
Points toA pathThe same inode as the original
Crosses filesystemsYesNo
Links to foldersYesNo
If the original is deletedLink breaksData stays reachable
Created withln -sln

Hard links are useful for space saving snapshots, which is how rsync --link-dest builds daily backups that share unchanged files. For almost everything else, use symbolic links.

Do permissions on a link matter?

No. A symlink always shows lrwxrwxrwx; access is checked on the target. Ownership of the link only matters in sticky folders like /tmp, where the kernel's protected_symlinks setting blocks following links owned by other users, a defense against classic temp file attacks. Leave that protection on.

Where do servers use symlinks every day?

  • /etc/nginx/sites-enabled/ on Debian and Ubuntu, linking to site files.
  • /etc/systemd/system/*.wants/, created by systemctl enable.
  • /etc/alternatives/, managing which java, editor or python version is default.
  • Release folders for apps, switched as shown above.
  • Moving a large data folder to a second drive while keeping the old path, though a bind mount from Linux mount command is often cleaner for services.

Can a symlink point to another symlink?

Yes, and chains are common: /usr/bin/java points to /etc/alternatives/java, which points to the real JDK binary. The kernel follows up to 40 links in a row before giving up with "too many levels of symbolic links", an error that almost always means a loop where a link points back at itself through another one. readlink -f or namei shows the chain so you can find where it circles.

Machines for Web Apps With Release Folders

ServerProcessorCores / threadsMemoryStorageNetworkPer monthSmallest order
E1Intel Xeon E3-1240 v34 / 816 GB DDR32x 240 GB SSD2x 1 Gbps$30.52$91.56 (3 months)
S1Intel Xeon E-2276G6 / 1264 GB DDR41x 1 TB NVMe2x 10 Gbps$53.32$53.32 (1 month)
S3Intel Xeon E-2356G6 / 1264 GB DDR42x 1 TB NVMe2x 10 Gbps$80.38$80.38 (1 month)

Keep Reading

Add a directory to PATH

Add a folder to PATH for your session, your user, every user or a systemd service, in the right order and without duplicates.

Open

The find command guide

A thorough guide to find: tests for name, type, size, time and owner, logical operators, pruning, actions, -exec forms and safe deletion.

Open

Linux mount command

Mount drives, partitions and network shares on Linux, make them permanent in fstab with UUIDs, and unmount safely when something is busy.

Open

Linux file permissions

Read ls -l output, understand owner, group and other bits, umask defaults, ACLs and why root and SELinux sit on top of it all.

Open

FAQ

Quick Answers

Target first, link name second: ln -s /real/path /link/path.

No. rm or unlink on the link removes only the link.

The link name pointed at an existing link to a folder. Use -n with -f to replace it.

Run find /path -xtype l.

Yes. Hard links cannot, but symbolic links can point anywhere.