Skip to main content

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

FlagDescription
-s, --symbolicMake symbolic links instead of hard links.
-f, --forceRemove existing destination files.
-v, --verbosePrint name of each linked file.
-i, --interactivePrompt whether to remove destinations.

Real-world Examples

  1. Create a hard link:

    ln original.txt hardlink.txt
  2. Create a symbolic (soft) link:

    ln -s /path/to/original.txt softlink.txt
  3. Create a symbolic link to a directory:

    ln -s /var/www/html /home/user/webroot