Home·Terminal commands

ln

Files and directories

Usage

ln -s [target] [linkname]

Gives a file another name; a symlink made with -s can point anywhere but breaks when the target moves, and a relative target is read from the link's own directory.

Common flags

FlagMeaning
-sMake a symbolic link instead of a hard link
-fReplace the target if it already exists
-nWith -f, replace a symlink to a directory instead of writing inside it
-iAsk before replacing
-vReport each link created

Examples

ln -s /opt/app/bin/app /usr/local/bin/app

Puts the program on your PATH.

ln -sfn /srv/releases/v2 /srv/current

Repoints a current symlink at a new release.

ln data.csv hardlink.csv

A second name for the same bytes on the same filesystem.

Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does ln do?

Gives a file another name; a symlink made with -s can point anywhere but breaks when the target moves, and a relative target is read from the link's own directory.

Q. How do I type it?

ln -s [target] [linkname] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

5 are listed here; the full set is in man ln. This command sits under Files and directories.

Related commands

man page: man ln