files

ln

Creates hard or symbolic links between files. Symbolic links point to a path; hard links share the same inode.

ln [OPTION]... TARGET LINK_NAME

Common flags

Flag Purpose
-s Create a symbolic (soft) link
-f Remove an existing destination before linking
-n Treat LINK_NAME as a normal file when it is a symlink to a directory
-r Make symlinks relative to the link location
-v Print the name of each linked file

Examples

ln -s /opt/app/current app

Create a symlink named app pointing at the release directory

ln -sf /etc/nginx/sites-available/site /etc/nginx/sites-enabled/site

Atomically replace an existing enabled symlink

ln source.txt hardlink.txt

Create a hard link that shares source.txt's inode

ln -srv ../shared lib/shared

Create a verbose relative symlink

Gotcha

Hard links cannot span filesystems or point to directories; use -s for cross-mount or directory links.

Related commands

← All Linux commands · Linux cheat sheet