Index Index for
Section 1
Index Alphabetical
listing for L
Bottom of page Bottom of
page

ln(1)

NAME

ln - Make a hard link or a symbolic link to a file

SYNOPSIS

ln [-fs] sourcename [targetname] ln [-fs] sourcename... targetdirectory ln [-fns] sourcename targetname ln [-fns] sourcename... targetdirectory

STANDARDS

Interfaces documented on this reference page conform to industry standards as follows: ln: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags.

OPTIONS

-f Forces the removal of existing target path names before linking. -s [Tru64 UNIX] Creates symbolic links. -n [Tru64 UNIX] If the target already exists, do not create the link, and issue an error message. The -f option overrides the -n option. To use the -n option, the CMD_ENV environment variable must be set to svr4.

OPERANDS

sourcename Path name of a file to be linked. targetname The path name of the new directory entry to be created. targetdirectory 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. [Tru64 UNIX] 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 must be made to files in the local file system: they cannot span file systems and cannot refer to directories. [Tru64 UNIX] With the -s option, the command makes symbolic links, including Context Dependent Symbolic Links (CDSLs). A symbolic link contains the name of the file to which it is linked. The referenced file is used when an open() operation is performed 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 exists, the command aborts unless the -f option is used. SVID and System V Release 4 Conformance [Tru64 UNIX] 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. [Tru64 UNIX] 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 option, 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 options and with CMD_ENV not set. [Tru64 UNIX] 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: · [Tru64 UNIX] If the standard input is not a terminal, the command attempts to silently unlink targetname and link the source file to it. · [Tru64 UNIX] 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 target 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. · [Tru64 UNIX] 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

[Tru64 UNIX] You cannot link files across file systems without using the -s option. That is, links across file systems must be symbolic links.

EXIT STATUS

The following exit values are returned: 0 All the specified files were linked successfully. >0 An error occurred.

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 file name is created. If intro does exist and permissions 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 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. 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. 6. 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 lrwxrwxrwx 1 root system 11 Dec 13 14:00 /d2@ -> /d1/t1/ The path name for sourcename must be specified if the sourcename differs from that of the targetdirectory. If the path name is not specified, 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 directory /d1/t1.

ENVIRONMENT VARIABLES

The following environment variables affect the execution of ln: CMD_ENV [Tru64 UNIX] 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 option requires that this environment variable be set to svr4. LANG 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. LC_ALL If set to a non-empty string value, overrides the values of all the other internationalization variables. LC_CTYPE Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). LC_MESSAGES Determines the locale for the format and contents of diagnostic messages written to standard error. NLSPATH Determines the location of message catalogues for the processing of LC_MESSAGES.

SEE ALSO

Commands: cp(1), mv(1), rm(1) Functions: chmod(2), link(2), open(2), readlink(2), stat(2), symlink(2) Standards: standards(5) Command and Shell User's Guide

Index Index for
Section 1
Index Alphabetical
listing for L
Top of page Top of
page