1ln(1)                            User Commands                           ln(1)
2
3
4

NAME

6       ln - make hard or symbolic links to files
7

SYNOPSIS

9       /usr/bin/ln [-fns] source_file [target]
10
11
12       /usr/bin/ln [-fns] source_file... target
13
14
15       /usr/xpg4/bin/ln [-fs] source_file [target]
16
17
18       /usr/xpg4/bin/ln [-fs] source_file... target
19
20

DESCRIPTION

22       In  the  first  synopsis  form,  the ln utility creates a new directory
23       entry (link) for the file specified by source_file, at the  destination
24       path  specified by target. If target is not specified, the link is made
25       in the current directory. This first synopsis form is assumed when  the
26       final operand does not name an existing directory; if more than two op‐
27       erands are specified and the final is not  an  existing  directory,  an
28       error will result.
29
30
31       In  the  second  synopsis  form, the ln utility creates a new directory
32       entry for each file specified by a source_file operand, at  a  destina‐
33       tion path in the existing directory named by target.
34
35
36       The  ln  utility  may  be  used  to create both hard links and symbolic
37       links. A hard link is a pointer to a file and is indistinguishable from
38       the original directory entry. Any changes to a file are effective inde‐
39       pendent of the name used to reference the file. Hard links may not span
40       file systems and may not refer to directories.
41
42
43       ln  by  default creates hard links. source_file is linked to target. If
44       target is a directory, another file named  source_file  is  created  in
45       target and linked to the original source_file.
46
47
48       If  target  is  an existing file and the -f option is not specified, ln
49       will write a diagnostic message to standard error, do nothing more with
50       the current source_file, and go on to any remaining source_files.
51
52
53       A  symbolic  link is an indirect pointer to a file; its directory entry
54       contains the name of the file to which it is linked. Symbolic links may
55       span file systems and may refer to directories.
56
57
58       File  permissions for target may be different from those displayed with
59       an -l listing of the ls(1) command. To display the permissions of  tar‐
60       get, use ls -lL. See stat(2) for more information.
61
62   /usr/bin/ln
63       If  /usr/bin/ln  determines that the mode of target forbids writing, it
64       prints the mode (see chmod(1)), asks for  a  response,  and  reads  the
65       standard  input  for one line. If the response is affirmative, the link
66       occurs, if permissible. Otherwise, the command exits.
67
68   /usr/xpg4/bin/ln
69       When creating a hard link, and the source file  is  itself  a  symbolic
70       link, the target will be a hard link to the file referenced by the sym‐
71       bolic link, not to the symbolic link object itself (source_file).
72

OPTIONS

74       The  following  options  are  supported  for   both   /usr/bin/ln   and
75       /usr/xpg4/bin/ln:
76
77       -f    Links  files  without  questioning  the user, even if the mode of
78             target forbids writing. This is the default if the standard input
79             is not a terminal.
80
81
82       -s    Creates a symbolic link.
83
84             If  the  -s  option  is used with two arguments, target may be an
85             existing directory or a  non-existent  file.  If  target  already
86             exists  and is not a directory, an error is returned. source_file
87             may be any path name and need not exist. If it exists, it may  be
88             a  file  or  directory  and may reside on a different file system
89             from target. If target is an existing directory, a file  is  cre‐
90             ated  in  directory  target whose name is source_file or the last
91             component of source_file. This file is a symbolic link that  ref‐
92             erences  source_file.  If target does not exist, a file with name
93             target is created and it  is  a  symbolic  link  that  references
94             source_file.
95
96             If  the  -s  option  is used with more than two arguments, target
97             must be an existing directory or an error will be  returned.  For
98             each  source_file,  a link is created in target whose name is the
99             last component of source_file. Each new source_file is a symbolic
100             link to the original source_file. The files and target may reside
101             on different file systems.
102
103
104   /usr/bin/ln
105       The following option is supported for /usr/bin/ln only:
106
107       -n    If target is an existing file, writes  a  diagnostic  message  to
108             stderr  and  goes on to any remaining source_files. The -f option
109             overrides  this  option.  This  is  the  default   behavior   for
110             /usr/bin/ln and /usr/xpg4/bin/ln, and is silently ignored.
111
112

OPERANDS

114       The following operands are supported:
115
116       source_file    A path name of a file to be linked. This can be either a
117                      regular or special file. If the -s option is  specified,
118                      source_file can also be a directory.
119
120
121       target         The  path name of the new directory entry to be created,
122                      or of an existing directory in which the  new  directory
123                      entries are to be created.
124
125

USAGE

127       See largefile(5) for the description of the behavior of ln when encoun‐
128       tering files greater than or equal to 2 Gbyte ( 2^31 bytes).
129

ENVIRONMENT VARIABLES

131       See environ(5) for descriptions of the following environment  variables
132       that  affect  the execution of ln: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES,
133       and NLSPATH.
134

EXIT STATUS

136       The following exit values are returned:
137
138       0     All the specified files were linked successfully
139
140
141       >0    An error occurred.
142
143

ATTRIBUTES

145       See attributes(5) for descriptions of the following attributes:
146
147   /usr/bin/ln
148       ┌─────────────────────────────┬─────────────────────────────┐
149       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
150       ├─────────────────────────────┼─────────────────────────────┤
151       │Availability                 │SUNWcsu                      │
152       ├─────────────────────────────┼─────────────────────────────┤
153       │CSI                          │Enabled                      │
154       └─────────────────────────────┴─────────────────────────────┘
155
156   /usr/xpg4/bin/ln
157       ┌─────────────────────────────┬─────────────────────────────┐
158       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
159       ├─────────────────────────────┼─────────────────────────────┤
160       │Availability                 │SUNWxcu4                     │
161       ├─────────────────────────────┼─────────────────────────────┤
162       │CSI                          │Enabled                      │
163       ├─────────────────────────────┼─────────────────────────────┤
164       │Interface Stability          │Standard                     │
165       └─────────────────────────────┴─────────────────────────────┘
166

SEE ALSO

168       chmod(1),  ls(1),  stat(2),  attributes(5),  environ(5),  largefile(5),
169       standards(5)
170

NOTES

172       A  symbolic  link  to  a  directory  behaves differently than you might
173       expect in certain cases. While an ls(1) command on such a link displays
174       the files in the pointed-to directory, entering ls -l displays informa‐
175       tion about the link itself:
176
177         example% ln -s dir link
178         example% ls link
179         file1 file2 file3 file4
180         example% ls -l link
181         lrwxrwxrwx  1 user            7 Jan 11 23:27 link -> dir
182
183
184
185
186       When you change to a directory (see cd(1))  through  a  symbolic  link,
187       using  /usr/bin/sh or /usr/bin/csh, you wind up in the pointed-to loca‐
188       tion within the file system. This means that  the  parent  of  the  new
189       working  directory  is not the parent of the symbolic link, but rather,
190       the parent of the pointed-to directory.  This  will  also  happen  when
191       using  cd with the -P option from /usr/bin/ksh or /usr/xpg4/bin/sh. For
192       instance, in the following case, the final working  directory  is  /usr
193       and not /home/user/linktest.
194
195         example% pwd
196         /home/user/linktest
197         example% ln -s /usr/tmp symlink
198         example% cd symlink
199         example% cd ..
200         example% pwd
201         /usr
202
203
204
205
206       C  shell users can avoid any resulting navigation problems by using the
207       pushd and popd built-in commands instead of cd.
208
209
210
211SunOS 5.11                        25 Mar 2004                            ln(1)
Impressum