ln (host)

Create links to (aliases for) files

Syntax:

ln [option]... [-T] target link_name

ln [option]... target

ln [option]... target... directory

ln [option]... [-t] directory target...

Runs on:

Microsoft Windows

Options:

--backup[=version_control], -b
The long form option, --backup, makes a backup of each existing destination file and requires passing a mandatory version_control (i.e., version control method) argument.

The short form option, --b, performs the same operation but doesn't accept any arguments (i.e., the current version control method is used).

The version control method may be selected by passing an argument with --backup, or by setting the version_control environment variable. The values for version_control are:

  • none, off - never make backups (even if --backup is provided).
  • numbered, t - make numbered backups.
  • existing, nil - make numbered backups if numbered backups already exist, otherwise make simple backups.
  • simple, never - always make simple backups.
--directory, -d, -F
Allows a superuser to attempt to hard link directories. However, this operation will probably fail because of system restrictions, even for a superuser.
--force, -f
Remove existing destination files.
--interactive, -i
Prompts whether or not to remove destinations.
--logical, -L
De-reference targets that are symbolic links.
--no-dereference, -n
Treat link_name as a normal file if it's a symbolic link to a directory.
--physical, -P
Make hard links directly to symbolic links.
--relative, -r
Create symbolic links relative to link location.
--symbolic, -s
Make symbolic links instead of hard links.

Using -s ignores -L and -P. Otherwise, the last specified option controls behavior when a target is a symbolic link, where the default is -P.

--suffix[=suffix], -S
Override the default backup suffix.

The default backup suffix is '~', unless it's set with --suffix or simple_backup_suffix.

--target-directory[=directory], -t
Specify the directory in which to create the links.
--no-target-directory, -T
Always treat link_name as a normal file.
--verbose, -v
Print the name of each linked file.
--help
Returns the help output and exits.
--version
Returns version information output and exits.

Description:

The ln utility makes links between files. By default, it makes hard links; with the -s it makes symbolic (i.e., "soft") links.

If the destination path exists and you have write permission for the existing destination file, or if -f was specified, ln unlinks the destination, then creates the new link.

To create the new link, or replace a file with a link, you need write permissions for the directory in which the new link is going to reside.

Hard links are limited to within the same filesystem as the original file and aren't permitted on directories. With symbolic links, however, you can link any pathname to a file. A symbolic link is a special file that has the destination pathname as its data.

Examples:

Create a symbolic link to the directory /home/fred called /home/barney:

ln -s  /home/fred /home/barney

Exit status:

0
All the specified files were linked successfully.
>0
An error occurred.

Caveats:

When creating a symbolic link, ln doesn't check that the target named actually exists, or even that it's a valid pathname. If the file doesn't exist or if the target isn't a valid pathname, any attempts to use the link fail.

CAUTION:
If a destination path exists, and ln is interrupted before ending, the destination path may be removed before the new link is created.
Page updated: