manpagez: man pages & more
info coreutils
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.2 ln: Make links between files

ln makes links between files. By default, it makes hard links; with the ‘-s’ option, it makes symbolic (or soft) links. Synopses:

 
ln [option]… [-T] target linkname
ln [option]… target
ln [option]… targetdirectory
ln [option]… -t directory target

Normally ln does not remove existing files. Use the ‘--force’ (‘-f’) option to remove them unconditionally, the ‘--interactive’ (‘-i’) option to remove them conditionally, and the ‘--backup’ (‘-b’) option to rename them.

A hard link is another name for an existing file; the link and the original are indistinguishable. Technically speaking, they share the same inode, and the inode contains all the information about a file—indeed, it is not incorrect to say that the inode is the file. On all existing implementations, you cannot make a hard link to a directory, and hard links cannot cross file system boundaries. (These restrictions are not mandated by POSIX, however.)

Symbolic links (symlinks for short), on the other hand, are a special file type (which not all kernels support: System V release 3 (and older) systems lack symlinks) in which the link file actually refers to a different file, by name. When most operations (opening, reading, writing, and so on) are passed the symbolic link file, the kernel automatically dereferences the link and operates on the target of the link. But some operations (e.g., removing) work on the link file itself, rather than on its target. See (libc)Symbolic Links section `Symbolic Links' in The GNU C Library Reference Manual.

The program accepts the following options. Also see Common options.

-b
--backup[=method]

See section Backup options. Make a backup of each file that would otherwise be overwritten or removed.

-d
-F
--directory

Allow users with appropriate privileges to attempt to make hard links to directories. However, note that this will probably fail due to system restrictions, even for the super-user.

-f
--force

Remove existing destination files.

-i
--interactive

Prompt whether to remove existing destination files.

-n
--no-dereference

Do not treat the last operand specially when it is a symbolic link to a directory. Instead, treat it as if it were a normal file.

When the destination is an actual directory (not a symlink to one), there is no ambiguity. The link is created in that directory. But when the specified destination is a symlink to a directory, there are two ways to treat the user's request. ln can treat the destination just as it would a normal directory and create the link in it. On the other hand, the destination can be viewed as a non-directory—as the symlink itself. In that case, ln must delete or backup that symlink before creating the new link. The default is to treat a destination that is a symlink to a directory just like a directory.

This option is weaker than the ‘--no-target-directory’ (‘-T’) option, so it has no effect if both options are given.

-s
--symbolic

Make symbolic links instead of hard links. This option merely produces an error message on systems that do not support symbolic links.

-S suffix
--suffix=suffix

Append suffix to each backup file made with ‘-b’. See section Backup options.

-t directory
--target-directory=directory

Specify the destination directory. See section Target directory.

-T
--no-target-directory

Do not treat the last operand specially when it is a directory or a symbolic link to a directory. See section Target directory.

-v
--verbose

Print the name of each file after linking it successfully.

An exit status of zero indicates success, and a nonzero value indicates failure.

Examples:

 
Bad Example:

# Create link ../a pointing to a in that directory.
# Not really useful because it points to itself.
ln -s a ..

Better Example:

# Change to the target before creating symlinks to avoid being confused.
cd ..
ln -s adir/a .

Bad Example:

# Hard coded file names don't move well.
ln -s $(pwd)/a /some/dir/

Better Example:

# Relative file names survive directory moves and also
# work across networked file systems.
ln -s afile anotherfile
ln -s ../adir/afile yetanotherfile

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2017
Individual documents may contain additional copyright information.