$linuxjunkies
>

ln(1)

Create links between files, allowing the same file to be accessed by different names or paths.

UbuntuDebianFedoraArch

Synopsis

ln [OPTION]... [-T] TARGET LINK_NAME
ln [OPTION]... TARGET
ln [OPTION]... TARGET... DIRECTORY
ln [OPTION]... -t DIRECTORY TARGET...

Description

The ln command creates links to files. By default, it creates hard links, which are additional directory entries pointing to the same inode as the original file. Hard links share the same content and metadata, and deleting one link doesn't affect others until all references are removed.

Using the -s flag creates symbolic (soft) links, which are special files containing a path to the target. Symbolic links can span filesystems and point to directories, but break if the target is moved or deleted.

Links are useful for organizing files, creating shortcuts, maintaining multiple versions, and ensuring updates propagate automatically to all references.

Common options

FlagWhat it does
-s, --symbolicCreate symbolic links instead of hard links
-f, --forceRemove existing destination files without prompting
-i, --interactivePrompt before overwriting existing destination files
-n, --no-dereferenceTreat symlink destination as normal file (don't follow it)
-v, --verbosePrint each file as it's linked
-r, --relativeCreate symbolic links with relative paths
-P, --physicalMake hard links to symbolic link targets, not the symlinks
-t, --target-directory=DIRSpecify the target directory for link creation

Examples

Create a symbolic link named 'python' pointing to the python3 executable

ln -s /usr/bin/python3 python

Create a hard link to report.txt in the archive directory; both names refer to the same file content

ln /home/user/documents/report.txt /home/user/archive/report.txt

Create a relative symbolic link that points up two directory levels to config.conf

ln -s ../../config.conf config

Create or replace a symbolic link with force flag, updating the link even if it already exists

ln -sf /opt/nginx/nginx /usr/local/bin/nginx

Create a symbolic link to a log file, allowing monitoring from a different location

ln -s /var/log/app.log /home/user/logs/current.log

Create hard links of all .txt files in the current directory within the /backup directory

ln -t /backup *.txt

Create a hard link with verbose output showing the operation completed

ln -v source.c src_backup.c

Related commands