How can I create a symbolic link in Terminal?

What command is used to create a symbolic link/soft link?


Solution 1:

┌── ln(1) link, ln -- make links
│   ┌── Create a symbolic link.
│   │                         ┌── the optional path to the intended symlink
│   │                         │   if omitted, symlink is in . named as destination
│   │                         │   can use . or ~ or other relative paths
│   │                   ┌─────┴────────┐
ln -s /path/to/original /path/to/symlink
      └───────┬───────┘
              └── the path to the original file/folder
                  can use . or ~ or other relative paths
$ echo content > original
$ ln -s original symlink
$ ls -la original symlink
-rw-r--r--  1 grgarside  staff    8 28 Jan 18:44 original
lrwxr-xr-x  1 grgarside  staff    8 28 Jan 18:44 symlink -> original
$ cat symlink
content

For more information about ln(1) see the man page.

The path to the symlink is optional; if omitted, ln defaults to making a link with the same name as the destination, in the current directory:

$ cd ~/Documents
$ ln -s ../Pictures
$ ls -l Pictures
lrwxr-xr-x  1 user  staff  11 Feb  1 17:05 Pictures -> ../Pictures

To create a symlink to replace a system directory (e.g. if you want to have /Users pointing to another disk drive), you need to disable System Integrity Protection. You can re-enable it after the symlink is set up.

Solution 2:

The command is called ln. If used with the option -s it will create a symbolic link in the current directory:

ln -s /any/file/on/the/disk linked-file

Solution 3:

I know this question is explicitly asking about the Terminal, but if you're in GUI Land and don't want to enter Terminal Land, you can use SymbolicLinker. This puts a "Make Symbolic Link" option in your Services menu in Finder.

A context menu for a folder, showing a "Services" submenu, with "Make Symbolic Link" hilighted

A context menu for a symbolic link, with "Make Symbolic Link" hilighted

Solution 4:

It's just ln -s <source> <destination>.