1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
ln(P) ln(P)
NAME
ln - link files
SYNOPSIS
ln [-fs] source_file target_file
ln [-fs] source_file ... target_dir
DESCRIPTION
In the first synopsis form, the ln utility shall create
a new directory entry (link) at the destination path
specified by the target_file operand. If the -s option
is specified, a symbolic link shall be created for the
file specified by the source_file operand. This first
synopsis form shall be assumed when the final operand
does not name an existing directory; if more than two
operands are specified and the final is not an existing
directory, an error shall result.
In the second synopsis form, the ln utility shall create
a new directory entry (link), or if the -s option is
specified a symbolic link, for each file specified by a
source_file operand, at a destination path in the exist-
ing directory named by target_dir.
If the last operand specifies an existing file of a type
not specified by the System Interfaces volume of
IEEE Std 1003.1-2001, the behavior is implementation-
defined.
The corresponding destination path for each source_file
shall be the concatenation of the target directory path-
name, a slash character, and the last pathname component
of the source_file. The second synopsis form shall be
assumed when the final operand names an existing direc-
tory.
For each source_file:
If the destination path exists: <ol type="a">
If the -f option is not specified, ln shall write a
diagnostic message to standard error, do nothing more
with the current source_file, and go on to any remaining
source_files.
Actions shall be performed equivalent to the unlink()
function defined in the System Interfaces volume of
IEEE Std 1003.1-2001, called using destination as the
path argument. If this fails for any reason, ln shall
write a diagnostic message to standard error, do nothing
more with the current source_file, and go on to any
remaining source_files.
If the -s option is specified, ln shall create a sym-
bolic link named by the destination path and containing
as its pathname source_file. The ln utility shall do
nothing more with source_file and shall go on to any
remaining files.
If source_file is a symbolic link, actions shall be per-
formed equivalent to the link() function using the
object that source_file references as the path1 argument
and the destination path as the path2 argument. The ln
utility shall do nothing more with source_file and shall
go on to any remaining files.
Actions shall be performed equivalent to the link()
function defined in the System Interfaces volume of
IEEE Std 1003.1-2001 using source_file as the path1
argument, and the destination path as the path2 argu-
ment.
OPTIONS
The ln utility shall conform to the Base Definitions
volume of IEEE Std 1003.1-2001, Section 12.2, Utility
Syntax Guidelines.
The following option shall be supported:
-f Force existing destination pathnames to be
removed to allow the link.
-s Create symbolic links instead of hard links.
OPERANDS
The following operands shall be supported:
source_file
A pathname of a file to be linked. If the -s
option is specified, no restrictions on the type
of file or on its existence shall be made. If the
-s option is not specified, whether a directory
can be linked is implementation-defined.
target_file
The pathname of the new directory entry to be
created.
target_dir
A pathname of an existing directory in which the
new directory entries are created.
STDIN
Not used.
INPUT FILES
None.
ENVIRONMENT VARIABLES
The following environment variables shall affect the
execution of ln:
LANG Provide a default value for the internationaliza-
tion variables that are unset or null. (See the
Base Definitions volume of IEEE Std 1003.1-2001,
Section 8.2, Internationalization Variables for
the precedence of internationalization variables
used to determine the values of locale cate-
gories.)
LC_ALL If set to a non-empty string value, override the
values of all the other internationalization
variables.
LC_CTYPE
Determine 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).
LC_MESSAGES
Determine the locale that should be used to
affect the format and contents of diagnostic mes-
sages written to standard error.
NLSPATH
Determine the location of message catalogs for
the processing of LC_MESSAGES .
ASYNCHRONOUS EVENTS
Default.
STDOUT
Not used.
STDERR
The standard error shall be used only for diagnostic
messages.
OUTPUT FILES
None.
EXTENDED DESCRIPTION
None.
EXIT STATUS
The following exit values shall be returned:
0 All the specified files were linked successfully.
>0 An error occurred.
CONSEQUENCES OF ERRORS
Default.
The following sections are informative.
APPLICATION USAGE
None.
EXAMPLES
None.
RATIONALE
Some historic versions of ln (including the one speci-
fied by the SVID) unlink the destination file, if it
exists, by default. If the mode does not permit writing,
these versions prompt for confirmation before attempting
the unlink. In these versions the -f option causes ln
not to attempt to prompt for confirmation.
This allows ln to succeed in creating links when the
target file already exists, even if the file itself is
not writable (although the directory must be). Early
proposals specified this functionality.
This volume of IEEE Std 1003.1-2001 does not allow the
ln utility to unlink existing destination paths by
default for the following reasons:
The ln utility has historically been used to pro-
vide locking for shell applications, a usage that
is incompatible with ln unlinking the destination
path by default. There was no corresponding tech-
nical advantage to adding this functionality.
This functionality gave ln the ability to destroy
the link structure of files, which changes the
historical behavior of ln.
This functionality is easily replicated with a
combination of rm and ln.
It is not historical practice in many systems;
BSD and BSD-derived systems do not support this
behavior. Unfortunately, whichever behavior is
selected can cause scripts written expecting the
other behavior to fail.
It is preferable that ln perform in the same man-
ner as the link() function, which does not permit
the target to exist already.
This volume of IEEE Std 1003.1-2001 retains the -f
option to provide support for shell scripts depending on
the SVID semantics. It seems likely that shell scripts
would not be written to handle prompting by ln and would
therefore have specified the -f option.
The -f option is an undocumented feature of many histor-
ical versions of the ln utility, allowing linking to
directories. These versions require modification.
Early proposals of this volume of IEEE Std 1003.1-2001
also required a -i option, which behaved like the -i
options in cp and mv, prompting for confirmation before
unlinking existing files. This was not historical prac-
tice for the ln utility and has been omitted.
FUTURE DIRECTIONS
None.
SEE ALSO
chmod() , find , pax , rm , the System Interfaces volume
of IEEE Std 1003.1-2001, link(), unlink()
COPYRIGHT
Portions of this text are reprinted and reproduced in
electronic form from IEEE Std 1003.1, 2003 Edition,
Standard for Information Technology -- Portable Operat-
ing System Interface (POSIX), The Open Group Base Speci-
fications Issue 6, Copyright (C) 2001-2003 by the Insti-
tute of Electrical and Electronics Engineers, Inc and
The Open Group. In the event of any discrepancy between
this version and the original IEEE and The Open Group
Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be
obtained online at http://www.open-
group.org/unix/online.html .
POSIX 2003 ln(P)
|