ln Make links between files
Creates a second name for a file. By default it makes a hard link. With -s it makes a symbolic link (symlink), a small pointer to another path. You use it to give a file or folder a shortcut at a second location without copying the data.
Synopsis
ln [OPTION]... TARGET LINK_NAME
ln [OPTION]... TARGET... DIRECTORY
Common options
| Option or form | What it does |
|---|---|
-s | Make a symbolic link instead of a hard link |
-f | If the link name already exists, remove it first and then make the link |
-i | Ask before replacing an existing link name |
-v | Verbose: print each link as it is made |
-n | If the link name is a symlink to a folder, treat it as a plain file instead of going into the folder. Use with -f to replace such a symlink |
-h | macOS and BSD: same as -n |
-P | When hard linking a symlink, link to the symlink itself. -L, the macOS default, links to the file it points to |
Examples
ln -s notes.txt notes-link.txt
ln -s docs documentation
ln -v notes.txt notes-hard.txt
ln -s ../notes.txt ../app.log docs/
ln -s notes.txt current && ln -sfn app.log current
ln -s ~/projects/dotfiles/vimrc ~/.vimrc
Notes
- The argument order is the opposite of what many people expect: the existing file comes first and the new link name comes second. Think of it as the same order as cp.
- A relative symlink target is read from the folder the link sits in, not from your current folder. If ln -s ../notes.txt docs/ looks broken, check the path from inside docs/. An absolute path avoids the problem.
- A symlink can dangle. If you move or delete the target, the link stays but points at nothing. Hard links do not have this problem, because the data stays until the last name is removed.
- Hard links cannot point to folders and cannot cross filesystems. Symbolic links can do both.
- On macOS, ln -s file.txt will say 'File exists' if the name is taken. Add -f to replace it. GNU ln has an -r option for relative symlinks, which macOS ln does not have.
See also
Last reviewed 2026-10-07.