Manual Page Result
0
Command: ln | Section: 1 | Source: Digital UNIX | File: ln.1.gz
ln(1) General Commands Manual ln(1)
NAME
ln - Link to a file
SYNOPSIS
ln [-fs] sourcename [targetname]
ln [-fs] sourcename... targetdirectory
ln [-fns] sourcename targetname
ln [-fns] sourcename... targetdirectory
[Digital] The -n flag is valid only if the environment variable
CMD_ENV is set to svr4.
STANDARDS
Interfaces documented on this reference page conform to industry stan-
dards as follows:
ln: XPG4, XPG4-UNIX
Refer to the standards(5) reference page for more information about in-
dustry standards and associated tags.
FLAGS
Forces the removal of existing target path names before linking. [Dig-
ital] Creates symbolic links. [Digital] If the target already ex-
ists, do not create the link, and issue an error message. The -f flag
overrides the -n flag. This flag requires the environment variable
CMD_ENV to be set to svr4.
PARAMETERS
Path name of a file to be linked. The path name of the new directory
entry to be created. A path name of an existing directory in which new
entries are to be created.
DESCRIPTION
A link is a directory entry that refers to a file. Usually, sourcename
is an existing file, and targetname does not exist. Thus, targetname
becomes a new name, or pseudonym for sourcename. A file, together with
its size and all its protection information, can have several links to
it. There are two kinds of links: hard links and symbolic links.
[Digital] By default ln makes hard links. A hard link to a file is in-
distinguishable from the original directory entry. Changes to either
file affect both files. Hard links cannot span file systems and cannot
refer to directories.
[Digital] A symbolic link contains the name of the file to which it is
linked. The referenced file is used when an open() operation is per-
formed on the link. A stat() on a symbolic link returns the linked-to
file. An lstat() must be done to obtain information about the link. The
readlink() call can be used to read the contents of a symbolic link.
Symbolic links can span file systems and can refer to directories.
Given one or two arguments, ln creates a link to an existing sourcename
file. If targetname is omitted, then sourcename is used for the link,
but it must be created in a different directory than that of the source
file. If targetname is given, the link has that name. The targetname
can also be a directory in which to place the link; otherwise, it is
placed in the current directory. If only the directory is specified,
the link is made to the last component of the sourcename file.
Given more than two arguments, ln makes links to all the specified
files (sourcename) in the specified targetdirectory. The links made
have the same name as the files to which they are being linked.
If targetname exits, the command aborts unless the -f flag is used.
SVID and System V Release 4 Conformance
[Digital] When the environment variable CMD_ENV is set to svr4, the
behavior of the base ln command is compatible with its behavior under
System V Release 4. There is also a version of the ln command provided
in the System V habitat that is conformant with the SVID standard. For
more information on the System V habitat, see the Command and Shell
User's Guide.
This section documents the behavior of the habitat version, and of the
base version with CMD_ENV set to svr4, insofar as the behavior differs
from that of the base ln command without CMD_ENV set. This section
discusses only hard links.
[Digital] In contrast to the base ln command without CMD_ENV set,
these versions of ln silently overwrite an existing targetname if it is
not a directory and has write permission. The -n flag, available only
in the base command when CMD_ENV is set, prevents overwriting such an
existing target. Thus, for such an existing targetname, the base com-
mand ln -n with CMD_ENV set behaves the same as does the base command
ln with no flags and with CMD_ENV not set.
[Digital] If the targetname exists, is not a directory, and does not
have write permission, three possible conditions can exist, with each
condition producing a different behavior: [Digital] If the standard
input is not a terminal, the command attempts to silently unlink tar-
getname and link the source file to it. [Digital] If the standard in-
put is a terminal and the command line does not include the -f option,
the command prompts the user for permission to unlink targetname. The
habitat command compares the user response to the system defined values
for YESSTR and NOSTR. If the user response matches the value for
YESSTR, the command attempts to unlink the target file and link the
source file to targetname. If the user response matches NOSTR, the com-
mand aborts. Similarly, with the base command and CMD_ENV set, the op-
eration aborts unless the user response begins with a y. [Digital] If
the standard input is a terminal and the command line includes the -f
option, the command attempts to silently unlink targetname and link the
source file to it.
ENVIRONMENT VARIABLES
The following environment variables affect the execution of ln: [Digi-
tal] When this environment variable is set to svr4, the behavior of
the ln command is compatible with its behavior under System V Release
4. The -n flag requires that this environment variable be set to svr4.
Provides a default value for the internationalization variables that
are unset or null. If LANG is unset or null, the corresponding value
from the default locale is used. If any of the internationalization
variables contain an invalid setting, the utility behaves as if none of
the variables had been defined. If set to a non-empty string value,
overrides the values of all the other internationalization variables.
Determines the locale for the interpretation of sequences of bytes of
text data as characters (for example, single-byte as opposed to multi-
byte characters in arguments). Determines the locale for the format
and contents of diagnostic messages written to standard error. Deter-
mines the location of message catalogues for the processing of LC_MES-
SAGES.
NOTES
[Digital] You cannot link files across file systems without using the
-s flag.
EXAMPLES
The following example creates a link (also called an alias) to a file:
ln chap1 intro
The previous command links chap1 to the intro file. If intro does not
already exist, the file name is created. If intro does exist and per-
missions allow, the file is replaced by a link to chap1. The following
command forces the link even if intro exists and permissions do not al-
low it to be overwritten: ln -f chap1 intro
The previous command causes chap1 and intro to refer to the same file.
Any changes made to one file also appear in the other file. If one
name is deleted with the rm command, the file is not actually deleted
because it remains under the other name. The following command links a
file to the same name in an existing directory: ln index manual
The previous command links index to the new name manual/index. The
following command links several files to names in another directory: ln
chap2 jim/chap3 /u/manual
The previous command links chap2 to the new name /u/manual/chap2 and
links jim/chap3 to /u/manual/chap3. The following command uses ln with
pattern-matching characters: ln manual/* .
The previous command links all files in the directory manual into the
current directory (.), giving them the same names they have in manual.
Note that you must type a space between the * (asterisk) and the .
(dot). The following command creates a link to the final component of
a path name: ln -s /a/b/c/d/e
This creates a link, e, in the current directory to the file
/a/b/c/d/e. The following command creates a link to a directory. In
this example, t1 is a subdirectory under d1: ln -s /d1/t1 /d2
This creates a link from /d1/t1 to /d2 as follows: # ls -lF /d2 lrwxr-
wxrwx 1 root system 11 Dec 13 14:00 /d2@ -> /d1/t1/
The path name for sourcename must be specified if the sourcename dif-
fers from that of the targetdirectory. If the path name is not speci-
fied, a link is created to a file, not to the intended directory. For
example, if the path name was not specified in this example,
ls -s t1 /d2 creates a link to a file named t1, instead of the direc-
tory /d1/t1.
EXIT VALUES
The following exit values are returned:
All the specified files were linked successfully. An error occurred.
RELATED INFORMATION
Commands: cp(1), mv(1), rm(1)
Functions: chmod(2), link(2)/unlink(2), open(2), readlink(2),
stat(2)/fstat(2)/lstat(2), symlink(2)
Standards: standards(5)
Documents: Command and Shell User's Guide
delim off
ln(1)