ln(1)
Create links between files, allowing the same file to be accessed by different names or paths.
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
| Flag | What it does |
|---|---|
-s, --symbolic | Create symbolic links instead of hard links |
-f, --force | Remove existing destination files without prompting |
-i, --interactive | Prompt before overwriting existing destination files |
-n, --no-dereference | Treat symlink destination as normal file (don't follow it) |
-v, --verbose | Print each file as it's linked |
-r, --relative | Create symbolic links with relative paths |
-P, --physical | Make hard links to symbolic link targets, not the symlinks |
-t, --target-directory=DIR | Specify the target directory for link creation |
Examples
Create a symbolic link named 'python' pointing to the python3 executable
ln -s /usr/bin/python3 pythonCreate 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.txtCreate a relative symbolic link that points up two directory levels to config.conf
ln -s ../../config.conf configCreate or replace a symbolic link with force flag, updating the link even if it already exists
ln -sf /opt/nginx/nginx /usr/local/bin/nginxCreate a symbolic link to a log file, allowing monitoring from a different location
ln -s /var/log/app.log /home/user/logs/current.logCreate hard links of all .txt files in the current directory within the /backup directory
ln -t /backup *.txtCreate a hard link with verbose output showing the operation completed
ln -v source.c src_backup.c