ln(1)									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

  The -n flag is valid only if the environment variable CMD_ENV is set to
  svr4.

FLAGS

  -f  Forces the removal of existing target pathnames before linking.

  -s  Creates symbolic links.

  -n  If the target already exists, do not create the link, and issue an
      error message. -f overrides -n. Requires the environment variable
      CMD_ENV to be set to svr4. This mimics the behavior of the ln command
      with no flags when CMD_ENV is not set.

DESCRIPTION

  A link is a directory entry that refers to a file. Typically, sourcename is
  an existing file, and targetname does not exist. 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.

  By default ln makes hard links. A hard link to a file is indistinguishable
  from the original directory entry.  Changes to either file affect both
  files. Hard links cannot span file systems and cannot refer to directories.

  A symbolic link contains the name of the file to which it is linked. The
  referenced file is used when an open(2) operation is performed on the link.
  A stat(2) on a symbolic link returns the linked-to file. An lstat(2) must
  be done to obtain information about the link. The readlink(2) 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 directory (targetdirectory). The links made
  have the same name as the files to which they are being linked.

  If targetname exits, the command will abort unless the -f flag is set.

  SVID and System V Release 4 Conformance

  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 Sys-
  tem V habitat, see the Command and Shell User's Guide. This section docu-
  ments 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 so set. This section discusses only hard links.

  In contrast to the base ln command without CMD_ENV set, these versions of
  ln will 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 command ln -n with CMD_ENV set
  behaves the same as does the base command ln with no flags and with CMD_ENV
  not set.

  If the targetname exists, is not a directory, and does not have write per-
  mission, three possible conditions can exist, with each condition producing
  a different behavior:

    +  If the standard input is not a terminal, the command attempts to
       silently unlink targetname and link the source file to it.

    +  If the standard input 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 tar-
       get file and link the source file to targetname. If the user response
       matches NOSTR, the command aborts. Similarly, with the base command
       and CMD_ENV set, the operation aborts unless the user response begins
       with a y.

    +  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.

NOTES

  You cannot link files across file systems without using the -s flag.

EXAMPLES

   1.  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 filename 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
       allow 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.

   2.  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.

   3.  The following command links several files to names in another direc-
       tory:
	    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.

   4.  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).

   5.  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.

RELATED INFORMATION

  Commands:  cp(1), mv(1), rm(1).

  Functions:  chmod(2), link(2), readlink(2), symlink(2), unlink(2).