Back to the command reference

ln

FilesFundamentals In simulator In real Linux

Create hard or symbolic links

Name: ln = link

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

ln creates links. By default it makes a hard link: another name for the same data (the same inode); the data survives as long as any name remains. Hard links can't cross file systems or point to directories.

-s makes a symbolic (soft) link: a small file holding a path, like a shortcut. It can cross file systems and point to directories, but breaks if the target is removed.

Syntax

ln [OPTION]... TARGET LINK_NAME

Common options

-s / --symbolicCreate a symbolic (soft) link; the usual choice
-f / --forceRemove an existing destination
-n / --no-dereferenceTreat a link to a directory as a normal file
-r / --relativeWrite a relative path into the symbolic link (it survives moving the whole tree)
-i / --interactiveAsk before replacing an existing file
-v / --verbosePrint each link made

Examples

  • $ ln -s /var/log/nginx logs-nginx

    Make a shortcut to a directory

    Explain
  • $ ln -sf config.prod.yml config.yml

    Repoint a link to another file

    Explain
  • $ ln data.txt data-hard.txt

    Hard link: two names for the same data

    Explain

Related