ln
Quick Reference
Command Name:
ln
Category:
file management
Platform:
linux
Basic Usage:
Common Use Cases
Syntax
ln [OPTION]... [-T] TARGET LINK_NAME ln [OPTION]... TARGET ln [OPTION]... TARGET... DIRECTORY ln [OPTION]... -t DIRECTORY TARGET...
Options
Option | Description |
---|---|
-s, --symbolic | Make symbolic links instead of hard links |
-f, --force | Remove existing destination files |
-b, --backup | Make a backup of each existing destination file |
-n, --no-dereference | Treat destination that is a symlink to a directory as if it were a normal file |
-i, --interactive | Prompt whether to remove destinations |
-r, --relative | Create symbolic links relative to link location |
-t, --target-directory=DIRECTORY | Specify the DIRECTORY in which to create the links |
-T, --no-target-directory | Treat LINK_NAME as a normal file always |
-v, --verbose | Print name of each linked file |
Examples
How to Use These Examples
The examples below show common ways to use the ln
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
ln file.txt link.txt
Creates a hard link named link.txt that points to file.txt. Both filenames will access the same data.
ln -s file.txt symlink.txt
Creates a symbolic link named symlink.txt that points to file.txt. The symbolic link is a special file that refers to the target file.
ln -s /path/to/directory linkname
Creates a symbolic link to a directory. This is only possible with symbolic links, not hard links.
ln -s /absolute/path/to/file /absolute/path/to/symlink
Creates a symbolic link using absolute paths. This ensures the link works regardless of the current working directory.
Advanced Examples:
ln -sf target.txt existing_symlink.txt
Creates or replaces a symbolic link. The -f option forces the creation by removing the destination file if it exists.
ln -s file1.txt file2.txt destination_directory/
Creates symbolic links to multiple files in the specified destination directory. The links will have the same names as the original files.