ln (Link)
Explanation
The ln command creates links between files. There are two types of links: hard links (which point directly to the data on the disk) and symbolic (soft) links (which point to the filename). Soft links are much more common and act like shortcuts in Windows.
Basic Syntax
ln [OPTION]... TARGET LINK_NAME (1st form)
ln [OPTION]... TARGET... DIRECTORY (2nd form)
Common Flags and Options
| Flag | Description |
|---|---|
-s, --symbolic | Make symbolic links instead of hard links. |
-f, --force | Remove existing destination files. |
-v, --verbose | Print name of each linked file. |
-i, --interactive | Prompt whether to remove destinations. |
Real-world Examples
-
Create a hard link:
ln original.txt hardlink.txt -
Create a symbolic (soft) link:
ln -s /path/to/original.txt softlink.txt -
Create a symbolic link to a directory:
ln -s /var/www/html /home/user/webroot