How to Create Symbolic Soft Link in Linux using ln Command

February 27, 2026 / Tutorial

A symbolic link (also called a soft link or symlink) is a special file that points to another file or directory. Think of it like a shortcut: when you open the link, the system follows it to the real target. Symlinks are useful for shorter paths, shared configs, version switching, and keeping multiple paths pointing to one location.

Types of Links in Linux

Linux supports two kinds of links:

  1. Symbolic (soft) links: A lightweight pointer to a path. If the original file is moved or deleted, the link breaks.
  2. Hard links: Another directory entry for the same file data (inode). If the original name is removed, the data still exists via the hard link. Hard links cannot point to directories (in most setups) or across filesystems.

 

How Do I Create a Soft (Symbolic) Link?

Use the ln command with the -s option:

ln -s <target> <link_name>

<target>: the real file or directory you want to point to
<link_name>: the name (path) of the symlink you want to create

Example

ln -s /opt/app/current/config.yaml ~/config.yaml

This creates a symlink ~/config.yaml that points to /opt/app/current/config.yaml.

Tip: Prefer relative targets when linking inside the same project tree:

ln -s ../bin/tool ./tool

Relative links remain valid if the whole folder is moved elsewhere.

How to Use the ln Command

Common options you’ll actually use:

  • -s — create a symbolic link (without this, ln makes a hard link)
  • -f — force: overwrite an existing destination path
  • -n — treat link destination as a normal file if it’s a symlink to a directory (handy with -f)
  • -v — verbose: show what was done
  • -T — treat the destination as a normal file, not a directory (prevents “place inside dir” behavior)

Examples:

# Basic symlink
ln -s /var/www/html/index.html ~/index.html

# Verbose output
ln -sv /usr/local/bin/mytool /usr/bin/mytool

# Force overwrite an existing link or file
ln -sfn /etc/nginx/sites-available/app.conf /etc/nginx/sites-enabled/app.conf

Create a Symlink to a Directory

You create directory symlinks the same way:

ln -s /data/backups /mnt/backups

Now /mnt/backups behaves like a pointer to /data/backups.

Version switching example:

ln -sfn /opt/node-v20 /opt/node
# /opt/node now points to /opt/node-v20

How to Overwrite an Existing Symlink

If the link already exists and you want to repoint it:

ln -sfn <new_target> <existing_link>
  • -f removes the existing path
  • -n treats destination as a file (even if it’s a symlink to a dir)
  • -s keeps it symbolic

Example:

ln -sfn /opt/app/releases/2026-02-11 /opt/app/current

How to Delete or Remove Symlinks

Removing a symlink does not delete the target. It only removes the pointer.

Use any of the following:

# Remove by name
rm mylink

# Unlink explicitly
unlink mylink

# Remove a symlink to a directory (don’t use a trailing slash)
rm /path/to/linkdir
Important: Don’t add a trailing slash when removing a symlink to a directory:
# Correct
rm link_to_dir

# Avoid (may attempt to remove directory contents)
rm -r link_to_dir/

Verify and Inspect Symlinks

List with details:

ls -l
# output example: mylink -> /real/path/target
Show the symlink target:
readlink mylink
readlink -f mylink    # prints the absolute, canonical path
Find broken symlinks:
find /path -xtype l
# or to list only broken links:
find /path -L -type l

Practical Tips & Gotchas

  • Relative vs absolute: Use relative paths for links inside a project to make moves easier. Use absolute paths for system‑wide links.
  • Permissions: You need write permission to the directory where the link will live (not the target).
  • Cross‑filesystem: Symlinks can point across different disks or mounts. Hard links cannot.
  • Directories: Hard links to directories are generally restricted for safety. Symlinks are the standard for directories.
  • Trailing slashes: Avoid trailing / on the link name when creating or deleting; it can change behavior.
  • Backups & packaging: Some tools may archive the link itself, others may follow it—check your tool’s flags (e.g., tar’s –dereference).

Getting Help for ln

Built‑in help and manual pages provide the authoritative reference:

ln --help
man ln
These will show all options supported on your system (GNU coreutils may differ slightly from other Unix variants).

Conclusion

Symlinks are a simple, powerful way to redirect paths, share resources, and manage versions without copying files. Use ln -s to create them, -sfn to safely overwrite them, and rm or unlink to remove them. Verify with ls -l or readlink. With a few careful habits (relative paths, no trailing slashes, and the right flags, you’ll keep your links reliable and your filesystem tidy.

Learn how to redirect stdout and stderr to a file in Bash, capture logs efficiently, debug faster, and streamline script output management.