ln

Updated

September 4, 2026

Overview

ln creates links: hard links (default) or symbolic links (-s). Symlinks are path pointers and can cross filesystems and point at directories. Hard links are additional directory entries for the same inode, must stay on one filesystem, and generally cannot link directories on Linux.

Syntax

ln [options] target link_name
ln [options] target... directory
ln [options] -t directory target...

Common Options

Option Description
-s, --symbolic Create a symbolic link
-f, --force Remove existing destination files
-i, --interactive Prompt before removing destination
-n, --no-dereference Treat link_name as a normal file if it is a symlink to a dir
-v, --verbose Verbose
-r, --relative Create symlink with relative target path (GNU)
-T Always treat link_name as a normal file
-t DIR Directory to place links into
-b Backup destination before overwrite

Hard vs symbolic

Property Hard link Symlink
Cross filesystem No Yes
Point to directory No (normal Linux) Yes
Broken if target removed Still has data if any link remains Becomes dangling
Relative semantics N/A (inode) Stored path can be relative or absolute
ls -l Same inode, no -> Shows -> target

Examples with Explanations

Bulk into a directory

ln -s /usr/bin/python3 /usr/bin/pip3 ~/bin/
ln -t ~/bin -s /usr/local/bin/app

Inspect

ls -l link
readlink link
readlink -f link
stat link
namei -l /path/to/link

Common failure: relative target confusion

cd /tmp
ln -s file.txt link          # target is string "file.txt" relative to link’s directory

If you create the link elsewhere, a relative target resolves from the link’s directory, not your cwd at creation time (you stored a string).

Notes / Pitfalls

  • ln -s existing_dir name when name exists as directory may create name/existing_dir — use -T/-n and check.
  • Hard links to shared libraries/configs can confuse package upgrades; prefer symlinks for admin sugar.
  • Backup tools and containers may treat hard links specially (rsync -H).
  • Dangling symlinks are valid entries; tools may or may not follow them.
  • Permissions on a symlink are largely ignored on Linux; the target’s mode matters for access through the link.

2026-relevant notes

  • Blue/green deploys still use current symlink switches extensively.
  • Special filesystems (overlay, FUSE) may restrict hard links.
  • Prefer ln -sfn patterns carefully; test once in a throwaway path.

Additional Resources

  • man ln