How to create a symlink


Use a symlink (symbolic link) to create a reference to another file or directory:

$ ln -s <source> <destination>

Example

Given the following directory structure:

$ tree
.
└── path
    └── to
        └── source

You can create a symlink like below:

$ ln -s path/to/source path/to/target

You will now have the following:

$ tree
.
└── path
    └── to
        ├── target -> path/to/source
        └── source

But what if the target file already exists?

$ ln -s path/to/source path/to/target
ln: path/to/target: File exists

You can force an override with the -f option:

$ ln -sf path/to/source path/to/target

Also, if you don’t want the symlink to be relative, then make the path absolute:

$ ln -s "$(pwd)/path/to/source" path/to/target

This ensures the symlink still points to the expected location even if it’s moved.

For more information, check out the manual page for the ln command:

$ man ln