Quick take: The ln command creates links between files. Use ln -s target linkname for a symbolic link (a pointer to another path), and add -f to replace an existing link. Without -s you get a hard link.

Introduction

The ln command creates links — extra names that point to a file. The most common kind, the symbolic link (or symlink), is a small pointer to another path, much like a shortcut. Symlinks are everywhere in Linux: /usr/bin tools, configuration in /etc, and version switches like python pointing to python3.

This guide explains symbolic versus hard links, how to create and update them, and where each is useful.

Syntax

The basic syntax of the ln command is:

ln [OPTIONS] TARGET LINK_NAME

Symbolic Links vs Hard Links

A symbolic link is a separate file that stores the path to its target. If the target is moved or deleted, the symlink breaks (it becomes “dangling”). Symlinks can cross filesystems and link to directories.

A hard link is a second directory entry pointing to the exact same data on disk. The file's data is only removed when the last hard link is deleted. Hard links cannot cross filesystems or link to directories. For almost all everyday use, you want a symbolic link (ln -s).

Common Options and Parameters

The most useful options and parameters for the ln command:

OptionDescription
-sCreate a symbolic (soft) link instead of a hard link.
-fForce — remove an existing link or file at the destination first.
-nTreat an existing symlink to a directory as a normal file (for updating).
-rCreate a symlink with a relative path to the target.
-vVerbose — print the name of each linked file.
-iPrompt before overwriting an existing destination.

Practical Examples

Real ln commands you can run today:

# Create a symbolic link
ln -s /opt/app/current/bin/app /usr/local/bin/app
# Update an existing symlink to a new target
ln -sfn /opt/app/v2 /opt/app/current
# Create a relative symlink
ln -sr ../shared/config.yml config.yml
# Create a hard link
ln data.csv data-backup.csv
# Verbose symlink creation
ln -sv /var/log/app.log latest.log

Where Symlinks Are Used in Real Systems

Symlinks are everywhere in Linux administration. The most powerful pattern is the atomic release switch: deployments keep each version in its own directory and point a stable current symlink at the active one. Switching versions — or rolling back — is then a single, instant, atomic operation.

# Releases live in versioned directories
/srv/app/releases/2026-06-13/
/srv/app/releases/2026-06-12/

# 'current' points at the live release; repoint it atomically
ln -sfn /srv/app/releases/2026-06-13 /srv/app/current

You will also see symlinks used to enable Nginx sites (sites-enabled linking to sites-available) and to expose version-agnostic command names like python pointing to python3.

Troubleshooting Broken Symlinks

A broken (dangling) symlink points at a target that no longer exists. ls -l shows the link and its target, but the quickest way to find broken links across a tree is with find:

# List every broken symlink under a directory
find /srv/app -xtype l

# Resolve where a link actually points
readlink -f current

If a link broke because the whole project moved, the fix is usually to recreate it as a relative symlink with ln -sr, so the link survives future moves of the entire directory tree.

Tips and Best Practices

  • Use ln -sfn together when repointing a directory symlink (such as a current release link) — it forces the replacement and avoids creating a link inside the old target.
  • Check where a symlink points with ls -l or readlink -f linkname.
  • Prefer relative symlinks (-r) inside a project so the links keep working when the project is moved.

Final Thoughts

Symbolic links are one of the most useful organising tools in Linux — they let you point a stable name at a changing target, switch versions atomically, and share configuration without copying. Remember ln -s for a symlink, add -fn when updating a directory link, and reach for hard links only in the rare cases that call for them.

What is the difference between a symbolic link and a hard link?+

A symbolic link stores the path to another file and breaks if that file is moved or deleted. A hard link is another name for the same data on disk and keeps the data alive until every hard link is removed. Symlinks can cross filesystems and link directories; hard links cannot.

How do I create a symbolic link in Linux?+

Use ln -s target linkname, for example ln -s /opt/app/bin/app /usr/local/bin/app. The target comes first, the new link name second.

How do I update an existing symlink?+

Use ln -sfn newtarget linkname. The -f forces replacement of the existing link and -n prevents ln from following an existing directory symlink.

How do I see where a symlink points?+

Run ls -l linkname to see the arrow and target, or readlink -f linkname to resolve the full final path.

Why is my symlink broken?+

A symlink breaks when its target is renamed, moved, or deleted, leaving a dangling pointer. Recreate it with the correct target, or use a relative symlink (ln -sr) so it survives the whole tree being moved.

Need help with Linux servers or infrastructure?

Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.

Hire Me for Support