How to Create a Symlink in Linux: A Complete Guide

Symbolic links — commonly called symlinks — are one of Linux's most practical file system features. Once you understand how they work, you'll find yourself reaching for them constantly, whether you're managing configuration files, organizing project directories, or linking shared libraries.

What Is a Symlink?

A symbolic link is a special file that points to another file or directory. Think of it like a shortcut in Windows, but more deeply integrated into the operating system. When you open or execute a symlink, Linux transparently redirects you to the target it references.

There are two types:

TypePoints ToSurvives Target Deletion?Can Cross Filesystems?
Soft (Symbolic) LinkFile pathNo — becomes a broken linkYes
Hard LinkInode (actual data)Yes — data persistsNo

For most everyday tasks, soft symlinks are what people mean when they say "symlink." They're flexible, readable, and work across different drives or partitions.

The Basic ln Command Syntax 🔗

Creating a symlink in Linux uses the ln command with the -s flag (for symbolic):

ln -s [target] [link_name] 
  • target — the original file or directory you want to link to
  • link_name — the name and location of the symlink you're creating

Example: Linking a File

ln -s /home/user/documents/report.txt /home/user/desktop/report-shortcut.txt 

This creates a symlink called report-shortcut.txt on the desktop that points to the original file in documents. Any changes made through the symlink affect the original.

Example: Linking a Directory

ln -s /var/www/html/project /home/user/myproject 

Now myproject in your home directory behaves exactly like browsing to /var/www/html/project. Useful for web development workflows where you want quick access without moving files.

Verifying Your Symlink

After creating a symlink, confirm it's set up correctly with ls -l:

ls -l /home/user/desktop/report-shortcut.txt 

You'll see output like:

lrwxrwxrwx 1 user user 38 Jun 10 09:15 report-shortcut.txt -> /home/user/documents/report.txt 

The l at the start of the permissions string indicates a symbolic link. The -> arrow shows exactly where it points.

Using Absolute vs. Relative Paths

This is where many users run into trouble. Symlinks can use either absolute paths or relative paths, and the choice matters.

Absolute paths start from the root / and always work regardless of where the symlink lives:

ln -s /etc/nginx/nginx.conf /home/user/nginx.conf 

Relative paths are resolved from the symlink's own location, not from where you ran the command:

ln -s ../configs/nginx.conf nginx.conf 

Relative symlinks can break if you move the symlink to a different directory. Absolute paths are safer for most use cases, especially system-level configurations.

Overwriting an Existing Symlink

If a symlink already exists and you want to update it, add the -f (force) flag:

ln -sf /new/target/path /existing/symlink 

Without -f, Linux will return an error rather than silently overwrite.

Removing a Symlink

Deleting a symlink is straightforward — use rm or unlink:

rm /home/user/desktop/report-shortcut.txt 

or:

unlink /home/user/desktop/report-shortcut.txt 

⚠️ Important: Never use rm -r on a symlink pointing to a directory without being careful. If you accidentally add a trailing slash, some commands treat it as the directory itself rather than the link.

Common Use Cases That Shape the Approach

Where and why you're creating symlinks affects which approach makes the most sense:

  • System configuration management — Many admins symlink config files from a version-controlled repository into /etc/, keeping system configs tracked in Git without moving them
  • Multiple Python or Node versions — Tools like nvm and pyenv create symlinks in /usr/local/bin to switch active runtime versions
  • Shared library linking — Linux itself uses symlinks extensively in /lib and /usr/lib to allow versioned libraries (e.g., libssl.so -> libssl.so.3)
  • Web server document roots — Symlinking project folders into web-accessible directories is common in development environments
  • Dotfile management — Power users often symlink ~/.bashrc, ~/.vimrc, and similar files from a centralized dotfiles repository

Variables That Affect Your Setup 🖥️

Not every symlink scenario is identical. A few factors determine what works cleanly:

  • Filesystem type — Most Linux filesystems (ext4, xfs, btrfs) fully support symlinks. FAT32 and exFAT (common on USB drives) do not support symlinks at all
  • Cross-device linking — Soft symlinks work across partitions and drives; hard links do not
  • Permissions — You need write permission to the directory where the symlink will be created. System directories like /usr/bin typically require sudo
  • Relative vs. absolute path discipline — In scripts or portable configurations that move between machines, relative path choices can cascade into broken links across environments
  • Shell and tooling behavior — Some tools follow symlinks transparently; others (particularly backup tools like rsync) have flags controlling whether to follow or copy the link itself

The right combination of path style, link type, and location depends on whether you're solving a single-user convenience problem or configuring something at the system or infrastructure level — and those two contexts call for meaningfully different habits.